Qt World Summit: Submit your Presentation

Beginners documentation question

  • I've been going through the documentation on how to make a simple integration with QML to my c++ app (See http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-interactqmlfromcpp.html). I've ported over my code base and gotten it to work in qtcreator without any qml stuff (just to make sure I didnt need any special build flags). In qtcreator I created a new desktop 'Quick 2 Application', and again made sure I can run just my console stuff.. the problem now comes with creating my first simple signal.

    I've followed the documentation and tried multiple different things, but here I'll paste what was autogenerated (minus includes) and explain my problem.

    int main(int argc, char *argv[])
    QGuiApplication app(argc, argv);

    QtQuick2ApplicationViewer viewer;
    //What I want to add in but can't figure out how
    QObject *item = viewer.rootObject();
    basicAction* ba = new basicAction();
    QObject::connect(item, SIGNAL(qmlSignal(QString)), ba, SLOT(eoLogin()));


    QObject *item = viewer.rootObject();  is saying Can't convert QQuickItem to QObject. and I need to have QObject as the first parameter for ::connect. I've tried this with the engine/component way, and the view way without any luck.

    If anyone could help me out I'd really appreciate it. I just need to get to the point where I can start.


  • bq. and I need to have QObject as the first parameter for ::connect

    Not a QObject but a QObject derived, which QQuickItem is, since it inherits QObject.

  • Thanks for the quick reply, however I tried that

    QQuickItem item = viewer.rootObject();
    ba = new basicAction();
    QQuickItem::connect(item, SIGNAL(qmlSignal(QString)), ba, SLOT(eoLogin()));


    I also tried
    QObject::connect(item, SIGNAL(qmlSignal(QString)), ba, SLOT(eoLogin()));

    /home/jflowers/Programming/QT/eoQMLIntegration/main.cpp:26: error: no matching function for call to 'QObject::connect(QQuickItem*&, const char*, basicAction*&, const char*)'

    I guess, Ideally, I am asking if an updated/working documentation for this exists and where?

    Thanks in advance!

Log in to reply