开发者

qt c++ after close window terminating thread / program

i got this main;

#include <QtGui>
#include <iostream>
using namespace std;
#include "tray.h"

void main(int argc, char *argv[])
 {
    QApplication app(argc, argv);
    Tray iets;
    app.exec();
 }

when i open in tray something like;

QFileDialog *dialog = new QFileDialog;
QString dir;

QString test = dialog->getOpenFileName(NULL, NULL, NULL, "Battlefield (*.exe)", NULL, NULL);
for(int i=0; i<test.split("开发者_Go百科/").size()-1; i++)
    dir+= test.split("/").at(i) + "/";
ui->lePath->setText(test);

and i choosed the file its terminating another thread / the program.

how to fi xit?


I don't know (and can't guess) what your Tray class is.

However, Qt usually terminate the program when the last displayed window (QWidget instance) is closed. Unless specified otherwise.

If Tray is not a window (a child class of QWidget), then app.exec() has no message loop to process and returns immediately, thus terminating the program.

What would you expect/what do you want your program to do at this point exactly ?


Not directly related but still important:

Your main() function really should return an exit status. You can simply change your main() so that it looks like:

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    Tray iets;
    return app.exec(); // app.exec() returns an exit status.
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜