c++ - How to mock a QML component -
actually i'm trying run test on qml component embeds c++ objects. unfortunately, i'm getting errors when execute tests. c++ objects aren't recognized qml file. makes sense c++ objects set in main.cpp file.
my question is: how can mock context property performing qml tests? or other said, how can unit-test mixing qt/qml code?
as understand right, got same problem i. time ago wrote mock: https://bitbucket.org/troyane/qml-cpp-template (you can use code free purposes).
take @ main.cpp
, there can see 2 ways of doing things:
// 1 case: // register type , create object @ qml side qmlregistertype<cppclass>("cppclassmodule", 1, 0, "cppclass"); qqmlapplicationengine engine(qurl("qrc:///qml/main.qml")); qdebug() << "qt version: " << qversion(); // 2 case: // create object here , "move up" qml side // engine.rootcontext()->setcontextproperty("cppclass", new cppclass);
good luck!
Comments
Post a Comment