I am running a Qt Desktop Application on CentOS 6.4 with Qt 5 Libraries.
When I start the application from VNC, as some of our servers do not have monitors, the application crashes. Starting from:
QApplication a(argc, argv);
I have tracked this down to a core file call qxcbconnection.cpp and the line:
xcb_create_window(m_connection, XCB_COPY_FROM_PARENT,
m_connectionEventListener, m_screens.at(0)->root(),
0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_ONLY,
m_screens.at(0)->screen()->root_visual, 0, 0);
The problem is, if there is no monitor connected then, m_screens is empty, and therefore causes an "index out of bounds" error.
My question is: Is there a way to get around this, or perhaps mimic a monitor somehow?
You may have found a regression bug in Qt, as I don't find anything relevant in the Qt4 to Qt5 changelog nor in the QtApplication documentation . IMHO it should not crash , and should just do unnecessary work (like in Qt4). However you can choose which type of instance you want to create. The doc gives an minimal example :
QCoreApplication* createApplication(int &argc, char *argv[])
{
for (int i = 1; i < argc; ++i)
if (!qstrcmp(argv[i], "-no-gui"))
return new QCoreApplication(argc, argv);
return new QApplication(argc, argv);
}
int main(int argc, char* argv[])
{
QScopedPointer<QCoreApplication> app(createApplication(argc, argv));
if (qobject_cast<QApplication *>(app.data())) {
// start GUI version...
} else {
// start non-GUI version...
}
return app->exec();
}
Ps : note that QApplication
underwent a major change behind the curtains, even if the API didn't change as much.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.