Seite 1 von 1

2. statischer QInputDialog nach QFileDialog schließt sofort

Verfasst: 18. Juni 2011 12:17
von LinusA
Hi!

Zuerst muss ich sagen, dass ich mein Problem schon in zwei englischen Foren gepostet habe, aber da noch keine Lösung gefunden wurde, bzw. dass ich noch nach Ideen (oder auch Tests) suche, wie man das lösen könnte (die Links dazu sind http://www.qtforum.org/article/36071/2n ... loses.html und http://developer.qt.nokia.com/forums/viewthread/6896 ).

Hauptproblem ist, dass ich QInputDialog::getItem() und QFileDialog::getOpenFileName() benutze, und dann die folgenden Dialoge von QInputDialog::getItem() sofort automatisch geschlossen werden. Das passiert übrigens für folgende QFileDialog::getOpenFileName() nicht.


Meine main-Methode:

Code: Alles auswählen

int main(int argc, char *argv[]) {
   QApplication app(argc, argv);

   CMain myMain(&app);
   QTimer::singleShot(0, &myMain, SLOT(doMain()));

   int returnVal = app.exec();
   cout << "Press ENTER to exit..." << endl;
   getchar();
   return returnVal;
}//end main
Header der benutzten Klasse CMain:

Code: Alles auswählen

class CMain : public QObject {
   Q_OBJECT

public:
   CMain(QObject *parent);
   ~CMain();

public slots:
   void doMain();

private:
};//end class
Problematische Methode im Body von CMain:

Code: Alles auswählen

void CMain::doMain() {

   QStringList myItems;
   myItems << "Item 1" << "Item 2" << "Item 3";

   // this all works!
   QInputDialog::getItem(nullptr, "Test input 1", "Choose:", myItems);
   QFileDialog::getOpenFileName(nullptr, "Open some file", QString(), tr("All files (*.*)"), nullptr, QFileDialog::ReadOnly);

   // now, this dialog will pop up ("flash") and close immediately
   QInputDialog::getItem(nullptr, "Test input 2", "Choose 2nd time:", myItems);

   // this works again!
   QFileDialog::getOpenFileName(nullptr, "Open another file", QString(), tr("All files (*.*)"), nullptr, QFileDialog::ReadOnly);

   cout << "doMain() done. Time to quit()." << endl;
   qApp->quit();

}//end method
Ich hab das Projekt mal als Visual Studio 2008 Solution (und als exportierte .pro-Datei) angehängt. Ich nutze Windows 7 32bit und WinXP SP3 32bit.

Vielen Dank schonmal für jegliche Kommentare!

Gruß, Linus

Verfasst: 18. Juni 2011 13:44
von LinusA
Hab das Programm gerade noch etwas weiter verändert, und das Problem tritt auch für QMessageBox und QErrorMessage auf. Hier die alternative Version von doMain():

Code: Alles auswählen

void CMain::doMain() {
	// check that the message box is working as expected!
	QMessageBox::information(nullptr, "Test Msgbox", tr("Qt Version: %1").arg(QT_VERSION_STR));

	// THIS QFILEDIALOG BREAKS SOMETHING! 
	// comment the next line out to see everything working normal!
	QFileDialog::getOpenFileName(nullptr, "Open some file", QString(), tr("All files (*.*)"), nullptr, QFileDialog::ReadOnly);

	// you'll hear the message box sound, but don't see anything
	QMessageBox::warning(nullptr, "Test Msgbox 2", "Hi, I'm another msg box");

	// the error msg will show up, but it will stay "unusable" in the background
	// also the program will execute the following file dialog at the same time without waiting
	QErrorMessage ErrMsg;
	ErrMsg.setModal(true);
	ErrMsg.showMessage(tr("This is some sort of error message"));
	ErrMsg.exec();

	// this pops up too early
	QFileDialog::getOpenFileName(nullptr, "Open another file", QString(), tr("All files (*.*)"), nullptr, QFileDialog::ReadOnly);

	cout << "doMain() done. Time to quit()." << endl;
	qApp->quit();
}//end method