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. [SOLVED]QML Slots & Cpp Signal
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]QML Slots & Cpp Signal

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.6k 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.
  • W Offline
    W Offline
    Wroman
    wrote on 5 Apr 2013, 10:23 last edited by
    #1

    Hello !

    There's plenty of tutorials that explain how to make QML Signals available to cpp.

    But how do you connect QML slot to cpp Signal ?

    I've made this :

    main.cpp :
    @int main(int argc, char *argv[])
    {
    QGuiApplication app(argc, argv);

    QQuickView view(QUrl::fromLocalFile("qml/my_hmi/main.qml"));
    QQuickItem *item = view.rootObject();
    
    HMIManager* manager = new HMIManager();
    ImageManager* im = manager->getImageManager(); //Image manager inhertis from Q_Object
    
    QObject::connect(*im,
                     SIGNAL(imageChanged(QVariant)),
                     *item,
                     SLOT(changeMainImage(QVariant)));
    
    view.show();
    return app.exec();
    

    }
    @

    main.qml :
    @
    [...]
    function changeMainImage(src)
    {
    mainImg.source = src;
    console.log("Hello Wolrd !")
    }//slot
    [...]
    @

    ImageManager :
    @
    #include <QtCore/QString>
    #include <QtCore/QMap>
    #include <QtCore/QVector>
    #include <QtGui/QImage>
    using namespace std;

    #ifndef ImageManager_h
    #define ImageManager_h

    class HMIManager;

    class ImageManager : public QObject
    {

    Q_OBJECT
    

    public:

    explicit ImageManager();
    ~ImageManager();
    

    enum E_ImageType
    {
    VIS_IMG = 0,
    SUPIMP_IMG = 1,
    DEC_G_IMG = 2,
    RAW_G_IMG = 3,
    RAW_G_MTX = 4
    };

    enum E_Direction
    {
    Left = 0,
    Right = 1,
    Up = 2,
    Down = 3
    };

    signals:

    void imageChanged(QVariant src);
    

    [...]
    }
    @

    But it asks me :

    C:\Dvl[...]\src\main.cpp:34: erreur : no matching function for call to 'QObject::connect(ImageManager&, const char*, QQuickItem&, const char*)'

    Any clues ?

    Trust me, i'm an engineer !

    1 Reply Last reply
    0
    • U Offline
      U Offline
      utcenter
      wrote on 5 Apr 2013, 11:16 last edited by
      #2

      QObject::connect uses pointers for the connection syntax. Why do you dereference your pointers?

      1 Reply Last reply
      0
      • W Offline
        W Offline
        Wroman
        wrote on 5 Apr 2013, 11:31 last edited by
        #3

        Oops sure. ^^'

        Now, it's just :

        @C:\Dvl[...]\src\main.cpp:34: erreur : no matching function for call to 'QObject::connect(ImageManager*&, const char*, QQuickItem*&, const char*)'@

        Was just a stupid problem of import...

        Trust me, i'm an engineer !

        1 Reply Last reply
        0

        1/3

        5 Apr 2013, 10:23

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved