Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Connect qt with qml
Forum Updated to NodeBB v4.3 + New Features

Connect qt with qml

Scheduled Pinned Locked Moved C++ Gurus
3 Posts 2 Posters 1.3k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Maco10
    wrote on last edited by
    #1

    Hello. I am making an easy program. I have a qml file with one button an one text field. When I write in the text field and click the button I want to the cpp part write a message in console. My problem is Qt program returns me
    QObject::connect: No such slot QApplication::newValue() in ../Prueba/main.cpp:27

    My code is:

    main.qml
    @Rectangle {

    signal valueIntroduced();
    
    width: 440;
    height: 380;
    
    TextField {...}
        
    Button {
        id: bot;
    
        width: 100;
        height: 50;
    
        anchors.centerIn: parent;
    
        onClicked: {
            valueIntroduced();
        }
    
    }@
    

    main.cpp
    @QApplication app(argc, argv);

    QQmlEngine *engine_ = new QQmlEngine();
    
    QQuickView *view = new QQuickView(engine_, NULL);
    
    Control *obj = new Control();
    
    view->rootContext()->setContextProperty( "obj_", obj );
    
    view->setSource(QUrl(QStringLiteral("qrc:/main.qml")));
    
    view->show();
    
    QObject::connect(view->rootObject(), SIGNAL(valueChanged(QString)),
                     &app, SLOT(newValue()) );
    
    return app.exec();
    

    @

    control.h
    @class Control : public QObject
    {
    Q_OBJECT

    Q_PROPERTY(QString input READ getInput WRITE setInput NOTIFY inputChanged)
    

    public:
    explicit Control(QObject *parent = 0);

    public slots:
    void newValue() { qDebug() << "The text field has been modified"; }

    private:
    QString m_input;
    };
    @

    How can I fix my signal? Why fails?

    Thanks a lot.

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi, and welcome to the Qt Dev Net!

      [quote]
      @
      QObject::connect(view->rootObject(), SIGNAL(valueChanged(QString)),
      &app, SLOT(newValue()) );
      @
      [/quote]Which class should receive the signal? You need to connect to obj, not &app.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Maco10
        wrote on last edited by
        #3

        It is already running. Thanks a lot.

        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