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. signals and slots in QT Quick , firstqml to cpp and cpp to second qml
Forum Updated to NodeBB v4.3 + New Features

signals and slots in QT Quick , firstqml to cpp and cpp to second qml

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
9 Posts 3 Posters 771 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.
  • N Offline
    N Offline
    Nazeeruddin
    wrote on last edited by
    #1

    hello,
    I am trying to make an application where input.qml will send some data via a signal to the main.cpp and it will connect to handler.cpp via the connect function, and in return the main.cpp will send the received data to another file main.qml via signals and slots and it displays it. This is just the basic concept, i would like to know how to proceed.

    1 Reply Last reply
    0
    • 6thC6 Offline
      6thC6 Offline
      6thC
      wrote on last edited by
      #2

      https://doc.qt.io/qt-5/signalsandslots.html
      https://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html

      https://doc.qt.io/qt-5/qtqml-cppintegration-overview.html
      https://doc.qt.io/qt-5/qtqml-cppintegration-topic.html

      N 1 Reply Last reply
      2
      • 6thC6 6thC

        https://doc.qt.io/qt-5/signalsandslots.html
        https://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html

        https://doc.qt.io/qt-5/qtqml-cppintegration-overview.html
        https://doc.qt.io/qt-5/qtqml-cppintegration-topic.html

        N Offline
        N Offline
        Nazeeruddin
        wrote on last edited by
        #3

        @6thC please look at my code

        #include <QGuiApplication>
        #include <QQmlApplicationEngine>
        #include <QtQuick>
        #include "handler.h"
        
        int main(int argc, char *argv[])
        {
            QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        
            QGuiApplication app(argc, argv);
        
            QQmlApplicationEngine engine;
            engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
            QObject *topLevel = engine.rootObjects().value(0);
            QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
            QQmlApplicationEngine engine1;
            engine1.load(QUrl(QStringLiteral("qrc:/inputfile.qml")));
            handler handler;
            QObject *topLevel1 = engine1.rootObjects().value(0);
            QQuickWindow *window1 = qobject_cast<QQuickWindow *>(topLevel1);
        
            QObject::connect(window1, SIGNAL(sendText(QString,QString,QString,QString)),
                             &handler, SLOT(handleText(QString,QString,QString,QString)));
            QObject::connect(&handler, SIGNAL(writeText(QVariant,QVariant,QVariant,QVariant)),
                                 window, SLOT(writeText(QVariant,QVariant,QVariant,QVariant)));
        
            return app.exec();
        }
        

        i am using QQmlApplicationEngine and it is working fine, but I want to use QQuick view and it is giving me error, can you tell me why that is happening

        QQuickView view;
        view.setSource(QUrl(QStringLiteral("qrc:/main.qml")));
        QQuickItem* x = view.rootObject();
        QQuickView view1;
        view.setSource(QUrl(QStringLiteral("qrc:/inputfile.qml")));
        QQuickItem* x1 = view.rootObject();
        

        this is the part of code when replaced with the qml file giving an error. please let me know, thanks

        jsulmJ 1 Reply Last reply
        0
        • N Nazeeruddin

          @6thC please look at my code

          #include <QGuiApplication>
          #include <QQmlApplicationEngine>
          #include <QtQuick>
          #include "handler.h"
          
          int main(int argc, char *argv[])
          {
              QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
          
              QGuiApplication app(argc, argv);
          
              QQmlApplicationEngine engine;
              engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
              QObject *topLevel = engine.rootObjects().value(0);
              QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
              QQmlApplicationEngine engine1;
              engine1.load(QUrl(QStringLiteral("qrc:/inputfile.qml")));
              handler handler;
              QObject *topLevel1 = engine1.rootObjects().value(0);
              QQuickWindow *window1 = qobject_cast<QQuickWindow *>(topLevel1);
          
              QObject::connect(window1, SIGNAL(sendText(QString,QString,QString,QString)),
                               &handler, SLOT(handleText(QString,QString,QString,QString)));
              QObject::connect(&handler, SIGNAL(writeText(QVariant,QVariant,QVariant,QVariant)),
                                   window, SLOT(writeText(QVariant,QVariant,QVariant,QVariant)));
          
              return app.exec();
          }
          

          i am using QQmlApplicationEngine and it is working fine, but I want to use QQuick view and it is giving me error, can you tell me why that is happening

          QQuickView view;
          view.setSource(QUrl(QStringLiteral("qrc:/main.qml")));
          QQuickItem* x = view.rootObject();
          QQuickView view1;
          view.setSource(QUrl(QStringLiteral("qrc:/inputfile.qml")));
          QQuickItem* x1 = view.rootObject();
          

          this is the part of code when replaced with the qml file giving an error. please let me know, thanks

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Nazeeruddin said in signals and slots in QT Quick , firstqml to cpp and cpp to second qml:

          it is giving me error

          What about posting the actual error?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          N 1 Reply Last reply
          2
          • jsulmJ jsulm

            @Nazeeruddin said in signals and slots in QT Quick , firstqml to cpp and cpp to second qml:

            it is giving me error

            What about posting the actual error?

            N Offline
            N Offline
            Nazeeruddin
            wrote on last edited by
            #5

            @jsulm

            libpng warning: iCCP: known incorrect sRGB profile
            QQuickView does not support using a window as a root item. 
            
            If you wish to create your root window from QML, consider using QQmlApplicationEngine instead. 
            
            QQuickView does not support using a window as a root item. 
            
            If you wish to create your root window from QML, consider using QQmlApplicationEngine instead. 
            
            QObject::connect: Cannot connect (nullptr)::sendText(QString,QString,QString,QString) to handler::handleText(QString,QString,QString,QString)
            QObject::connect: Cannot connect handler::writeText(QVariant,QVariant,QVariant,QVariant) to (nullptr)::writeText(QVariant,QVariant,QVariant,QVariant)
            
            jsulmJ 1 Reply Last reply
            0
            • N Nazeeruddin

              @jsulm

              libpng warning: iCCP: known incorrect sRGB profile
              QQuickView does not support using a window as a root item. 
              
              If you wish to create your root window from QML, consider using QQmlApplicationEngine instead. 
              
              QQuickView does not support using a window as a root item. 
              
              If you wish to create your root window from QML, consider using QQmlApplicationEngine instead. 
              
              QObject::connect: Cannot connect (nullptr)::sendText(QString,QString,QString,QString) to handler::handleText(QString,QString,QString,QString)
              QObject::connect: Cannot connect handler::writeText(QVariant,QVariant,QVariant,QVariant) to (nullptr)::writeText(QVariant,QVariant,QVariant,QVariant)
              
              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Nazeeruddin said in signals and slots in QT Quick , firstqml to cpp and cpp to second qml:

              QQuickView does not support using a window as a root item.

              If you wish to create your root window from QML, consider using QQmlApplicationEngine instead.

              This tells you what the problem is.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              N 1 Reply Last reply
              3
              • jsulmJ jsulm

                @Nazeeruddin said in signals and slots in QT Quick , firstqml to cpp and cpp to second qml:

                QQuickView does not support using a window as a root item.

                If you wish to create your root window from QML, consider using QQmlApplicationEngine instead.

                This tells you what the problem is.

                N Offline
                N Offline
                Nazeeruddin
                wrote on last edited by
                #7

                @jsulm
                Can you please explain what it means, the thing is I am new to QT and want a clear idea, Thanks

                jsulmJ 1 Reply Last reply
                0
                • N Nazeeruddin

                  @jsulm
                  Can you please explain what it means, the thing is I am new to QT and want a clear idea, Thanks

                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Nazeeruddin "QQuickView does not support using a window as a root item" - well, it tells you that if you use QQuickView (what you do) you can't have Window as top element in your QML (root element).

                  "If you wish to create your root window from QML, consider using QQmlApplicationEngine instead." - and this tells you what you can use instead of QQuickView.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2
                  • 6thC6 Offline
                    6thC6 Offline
                    6thC
                    wrote on last edited by
                    #9

                    I'd also suggest using the https://wiki.qt.io/New_Signal_Slot_Syntax
                    The old syntax isn't as clean/concise - also doesn't provide you with compile time checks/safeties.

                    If you are like me: you'll break things more often than you want to and letting the compiler do that work instead means you don't have to.

                    Honestly, I'd start with the example projects bundled inside Qt Creator. Or even just a new application based on QtQuick template will get you a QML app started. Then you can use those integration links to do more.

                    The examples apps will get you something basic that starts and you can witness it working, take a copy of and start pulling that apart to understand.

                    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