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. Unit test for QML
Forum Update on Monday, May 27th 2025

Unit test for QML

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 1.5k Views
  • 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.
  • E Offline
    E Offline
    ephe
    wrote on last edited by
    #1

    I have written a couple of unit tests to test my QMLs already - passing values to QML, call functions and reading properties.

    @
    int argc(5);
    char** argv = new char *[5];
    argv[0] = "";
    argv[1] = "";
    argv[2] = "";
    argv[3] = "";
    argv[4] = "";
    QGuiApplication app(argc, argv);
    QQmlEngine engine;

    QQmlComponent component(&engine, QUrl("qrc:/myTest/Test.qml"));
    m_object = component.create();
    QMetaObject::invokeMethod(m_object, "myMethod", Q_ARG(QVariant, "test test"));
    QString str = QQmlProperty(m_object, "myString").read().toString();
    

    @

    This is working perfectly fine as long as I do not call any methods on the Canvas which use the context2d.

    @
    import QtQuick 2.0

    Item {
    property string myString
    Canvas
    {
    id: canvas
    }

    function myMethod(str)
    {
        myString = str
    }
    

    }
    @

    If I call methods on the context2d, I get the following message:
    Unable to use getContext() at this time, please wait for available: true

    I guess I need to make the canvas visible to test it? Are there any suggestions of how to do that or how I can "fake" the availability?

    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