Solved QXmlQuery Please instantiate the QApplication object first in static library
-
I'm learning about the QXMLQuery class usage in a static library. I'm getting a weird error I wouldn't expect.
I've created a unit test project that loads the static library and calls the public method:
QVariant DeviceConfig::selectConfigAttribute(QByteArray attributeXPath) { QString xml = "<begin>stuff</begin>"; QXmlQuery query; QXmlResultItems results; QXmlItem item; qDebug() << 11 << endl; query.setFocus(xml); qDebug() << 22 << endl; // more code here that happens after the error }
I get the following error:
QDEBUG : DeviceConfigTest::test_configSelectDeviceParameter() 11 QWARN : DeviceConfigTest::test_configSelectDeviceParameter() QCoreApplication::applicationFilePath: Please instantiate the QApplication object first QWARN : DeviceConfigTest::test_configSelectDeviceParameter() QEventLoop: Cannot be used without QApplication QWARN : DeviceConfigTest::test_configSelectDeviceParameter() QObject::startTimer: Timers can only be used with threads started with QThread QDEBUG : DeviceConfigTest::test_configSelectDeviceParameter() 22
It doesn't make sense to me that QXmlQuery would be coupled to QCoreApplication. Do you have any idea why I'm getting this error?
-
@Daniel-Williams said in QXmlQuery Please instantiate the QApplication object first in static library:
Do you have any idea why I'm getting this error?
Because it needs it - e.g. for QString locales and other stuff.
-
@Daniel-Williams said in QXmlQuery Please instantiate the QApplication object first in static library:
It doesn't make sense to me that QXmlQuery would be coupled to QCoreApplication. Do you have any idea why I'm getting this error?
https://doc.qt.io/qt-5/qxmlquery.html#resource-management
An instance of QCoreApplication must exist before QXmlQuery can be used.
-
Thank you. This is must be a result that I'm running this from a unit test and QCoreApplication isn't instantiated in the QTest framework. From what has been written, I'm comfortable that the error will go away when run from the actual appliction. Thank you.