您可以從任何地方輕鬆啓動GUI。例如:
class App_starter : public QObject {
Q_OBJECT
public:
App_starter(QString password) {
//performing password check request here
}
private slots:
void response() {
//read response
if (password_ok) {
Main_window* mw = new Main_window();
mw->show();
} else {
QApplication::quit();
}
}
};
//main()
QApplication app;
App_starter starter(app.arguments()[1]);
return app.exec();
你甚至可以發射不知道GUI:
class App_starter : public QObject {
//...
private slots:
void response() {
//read response
if (password_ok) {
emit password_ok();
} else {
QApplication::quit();
}
}
signals:
void password_ok();
};
//main()
QApplication app;
Main_window window;
App_starter starter(app.arguments()[1]);
connect(&starter, SIGNAL(password_ok()), &window, SLOT(show()));
return app.exec();
我不知道。現在它工作了!感謝您快速高效的回答! – Neptilo