[Qt-interest] Show Open-File-dialog on startup

Trenton Tuggle Trent at Tuggle.org
Tue Mar 24 15:03:56 CET 2009


I'd bet you need to do it after executing MainWidget->exec() or  
QApplication()::exec()... According to the comments above  
QApplication::exec(): "Generally speaking, no user interaction can  
take place before calling exec(). As a special case, modal widgets  
like QMessageBox can be used before calling exec(), because modal  
widgets call exec() to start a local event loop."

That makes it hard... If nothing else, the only thing that comes to  
mind is perhaps creating a QThread (maybe even in your main() function  
right before exec()) which would sleep for a few seconds then send  
your signal, then terminate itself (the thread).

You could, of course, try overloading show() and doing it there...  
don't know if that'd work.  The goal would be to get a hook after  
you've called QApplication::exec()... good luck.

-Trent Tuggle

On Mar 24, 2009, at 9:43 AM, Oliver Demetz wrote:

> Hi!
>
> My main widget is derived from QWidget
>
> class MainWidget : public QWidget
> {
> 	MainWidget()
> 	{	
> 		//bla...inititialisations
> 		load();
> 	};
>
> public slots:
> 	void load(void)
> 	{
> 		QString filename = QFileDialog::getOpenFileName(this,
> 		     tr("Open File"), "", tr("PNGs (*.png)"));
> 		// and so on...
> 	};
> }
>
> This construction leads to an immediate program abort with message:
>
> Fatal: ASSERT: "!parent ||parent- 
> >testAttribute(Qt::WA_WState_Created)"
> in file dialogs\qfiledialog_win.cpp, line 309
>
> Is there a signal being emitted after everything has been created  
> that I
> could connect to the load-slot?
>
> Thanks in advance,
> Oliver
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list