Newbie Question Regarding QML Q_INVOKABLE



  • Hello,

    This is my first post here in QT forums. I have been around for a week reading all your posts and learning from them. Unfortunately I am stuck with learning the basic concepts. I am currently working on trying to get my sample code for Q_INVOKABLE to compile. I was wondering If anyone could take a quick glance at my code and possibly maybe point me in the right direction as to why I might have these errors. In the meantime I will be around trying to see if I can answer some questions for other people.

    @
    #include <QtGui/QApplication>
    #include <QDeclarativeContext>
    #include <QProcess>
    #include "qmlapplicationviewer.h"

    class TvRemote : public QObject
    {
    Q_OBJECT
    public:

    Q_INVOKABLE void channelUp(){
        QProcess p;
        p.start("tvtime-command CHANNEL_UP" );
    
    }
    
    Q_INVOKABLE void channelDown(){
       QProcess p;
       p.start("tvtime-command CHANNEL_DOWN");
    }
    

    };

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QDeclarativeView view;
    TvRemote test;
    //view.rootContext()->setContextProperty("tvRemote",data);

    //view.setSource(QUrl::fromLocalFile&#40;"qml/testingThois/main.qml"&#41;);
    //view.setAttribute(Qt::WA_TranslucentBackground,true);
    //view.setWindowFlags(Qt::FramelessWindowHint);
    //view.viewport()->setAutoFillBackground(false);
    view.show();
    
    
    return app.exec();
    

    }
    @

    Errors:
    Undefined refrence to vtable for TvRemote 4 times
    collect2: ID returned 1 exit status

    thank you for any help you can provide!



  • You need to put your QObject classes in their own header files.

    Also, when you'll use your class in the QML later on, in order to use its invokable methods in the QML you need to first call "qmlRegisterType<TvRemote>()":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeengine.html#qmlRegisterType.


Log in to reply
 

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