Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Access QML Engine in QtQuickTest
Forum Updated to NodeBB v4.3 + New Features

Access QML Engine in QtQuickTest

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.1k 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.
  • Werner EisenbarthW Offline
    Werner EisenbarthW Offline
    Werner Eisenbarth
    wrote on last edited by Werner Eisenbarth
    #1

    I need to do some initialization in the QmlEngine utilized by a QtQuickTest.

    The test is build on TestCase items, which need global properties that are usually set by something like this on the C++ side:

    myQuickView->engine()->rootContext()->setProperty(..., ...);
    

    The C++ side currently only consists of:

    #include <QtQuickTest/quicktest.h>
    #include <QByteArray>
    
    static bool s_configEnv = qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
    
    QUICK_TEST_MAIN(inputpanel)
    

    (Yes, it is the test for the virtual keyboard ... g)

    How do I access the engine here before the tests are run?

    Kind regards.

    1 Reply Last reply
    0
    • benlauB Offline
      benlauB Offline
      benlau
      Qt Champions 2016
      wrote on last edited by
      #2

      Probably it don't have a direct way to access QQmlEngine owned by QtQuickTest. I usually use a dirty hack. I would register a Singleton QObject and let it configure QQmlEngine during construction.

      Example:

      testable/testrunnerwrapper.cpp at master · benlau/testable

      1. The provider() is called once the registered Singleton object is referred
      2. Then it will call a registered callback in another object
      3. It is a dirty hack. You must make sure the object is referred in the first test case. Otherwise, it may not be able to work as expected.

      However, in your case, provide the required data in a Singleton object would be much easier.

      Werner EisenbarthW 1 Reply Last reply
      1
      • benlauB benlau

        Probably it don't have a direct way to access QQmlEngine owned by QtQuickTest. I usually use a dirty hack. I would register a Singleton QObject and let it configure QQmlEngine during construction.

        Example:

        testable/testrunnerwrapper.cpp at master · benlau/testable

        1. The provider() is called once the registered Singleton object is referred
        2. Then it will call a registered callback in another object
        3. It is a dirty hack. You must make sure the object is referred in the first test case. Otherwise, it may not be able to work as expected.

        However, in your case, provide the required data in a Singleton object would be much easier.

        Werner EisenbarthW Offline
        Werner EisenbarthW Offline
        Werner Eisenbarth
        wrote on last edited by Werner Eisenbarth
        #3

        That did the trick, 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