[SOLVED]QML Slots & Cpp Signal



  • 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 ?



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



  • 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...


Log in to reply
 

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