Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QXmlQuery Please instantiate the QApplication object first in static library
Qt 6.11 is out! See what's new in the release blog

QXmlQuery Please instantiate the QApplication object first in static library

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 586 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daniel Williams
    wrote on last edited by
    #1

    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?

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • D Daniel Williams

        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?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @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.

        1 Reply Last reply
        2
        • D Offline
          D Offline
          Daniel Williams
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved