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. Newbie Question Regarding QML Q_INVOKABLE
QtWS25 Last Chance

Newbie Question Regarding QML Q_INVOKABLE

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 3.9k 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.
  • K Offline
    K Offline
    klok99ah
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      coyotte508
      wrote on last edited by
      #2

      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.

      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