Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Pagestack, push() from within C++



  • Hi,
    I need to push/pop pages on a pagestack within C++.
    I do use the invoke method @QMetaObject::invokeMethod(pageStack, "push", someparameter)@

    In javascript it should be:
    @pageStack.push(myPage)@

    (myPage is an id)
    but in the above c++ invokeMethod I cannot use an id parameter.
    Neither is QVariant-objectName or QString-objectName accepted by push:
    @QMetaObject::invokeMethod: No such method PageStack_QMLTYPE_4::push(QVariant)@

    r.



  • Did you try wrapping the argument in Q_ARG(type, value)?



  • Sorry,
    To be precise:
    @QMetaObject::invokeMethod(pageStack, "push", Q_ARG(QString, "instrumentPage"));@

    QMetaObject::invokeMethod: No such method PageStack_QMLTYPE_4::push(QString)
    and
    @QMetaObject::invokeMethod(pageStack, "push", Q_ARG(QObject*, instrumentPage));@

    QMetaObject::invokeMethod: No such method PageStack_QMLTYPE_4::push(QObject*)
    and several more combi's (like QVariant)
    r.



  • I guess your only option then is: read the source. Sorry, I don't know how this works exactly either :-)



  • Oh well, my reply completely disappeared after posting...
    Anyhow, I managed to avoid the error messages (push needed 3 args). Stil, it doesn't work.
    One of the so many problems with QML<>C++.
    Thanks for your help.
    I'll put up a more fundamental question: is QML matured enough to port large C++/QT applications to0 C++/QML?



  • The distinction you make isn't correct. QML is still Qt. But if you mean porting a now completely widget-based application to use a QML interface, I guess the answer is: it depends. It depends on your platform, on your needs, on the types of interaction you need to support...



  • Thanks,
    I have put up the general question here: http://qt-project.org/forums/viewthread/16009/
    r.



  • You need to call 'push' in such a way:

    QMetaObject::invokeMethod(pageStack, "push", Q_RETURN_ARG(QVariant, retValue),
    Q_ARG(QVariant, QVariant::fromValue(mainPage)), Q_ARG(QVariant, QVariant()), Q_ARG(QVariant, QVariant()));

    i.e. you need to take in account agruments count, which you can see in reference documentation.



  • Thanks.
    I'll have another try. Looks like the documentation has been updated as well.


Log in to reply