Stuck with Qt5.4 project.



  • Hello guys,

    I was trying to follow some guys tutorial from the web on integrating C++ and QML, did everything what he/she did but failed with 4 errors kinda the same sort. One of them says: " etMainQmlFile is not a member of QQmlApplicationEngine". Same for the others, rootObject is not a member of QQmlApplicationEngine and showExpanded is not.... . Any ideas on how to solve this? THank you.

    Here's the code. (main.cpp)

    @#include <QGuiApplication>
    #include <QQmlApplicationEngine>

    #include "qtquickglobal.h"
    #include <QQmlContext>
    #include "myclass.h"
    #include <QtCore>
    #include <QtDebug>
    #include <QQuickWindow>

    int main(int argc, char *argv[]){

    //Q_OBJECT;
    QGuiApplication app(argc, argv);
    
    QQmlApplicationEngine viewer;
    
    viewer.load(QUrl(QStringLiteral("Qt/Versuch2/main.qml")));
    
    myclass data;
    
    viewer.rootContext() ->setContextProperty("myclassData", &data);
    viewer.setMainQmlFile&#40;QStringLiteral("qml/Versuch2/main.qml"&#41;);
    
    QObject *viewerobject = viewer.rootObject();
    
    QObject::connect(viewerobject, SIGNAL(qmlSignal(QString)), &data, SLOT(cppSlot(QString)));
            viewer.showExpanded();
    
    return app.exec();
    

    }

    void myclass::cppSlot(QString msg) {

    qDebug() <<QString ("Called the cpp slot with message: %1").arg(msg);
    

    }
    @


  • Moderators

    I do not know enough about QML, but probably you have followed a tutorial for Qt 4 which is mainly, but not completely compatible with Qt5.
    You can download and install the older version of "Qt4.8":http://download.qt-project.org/archive/qt/ if you like to follow the tutorial.



  • No, actually it was a tutorial for Qt5.2 (I use 5.4), which surprised me quite a bit because there shouldn't be that many changes and incompatibilities between versions so close to each other.
    Thank you for the time You've taken to read it anyway.


  • Moderators

    Hi,

    The error messages are correct. QQmlApplicationEngine does not have any member functions called setMainQmlFile(). See http://doc.qt.io/qt-5/qqmlapplicationengine.html for a list of members that it actually has.

    I'm guessing that your tutorial used a custom class called QmlApplicationViewer or QtQuick2ApplicationViewer (not QQmlApplicationEngine!). These classes aren't actually part of the Qt API. You see them around because Qt Creator used to generate these custom classes for convenience. However, newer versions of Qt Creator use built-in Qt classes instead.

    I suggest you follow a different tutorial, like http://doc.qt.io/qt-5/qml-tutorial.html


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.