Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Calling c++ method from QML.
Forum Updated to NodeBB v4.3 + New Features

Calling c++ method from QML.

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 885 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.
  • AhtiA Offline
    AhtiA Offline
    Ahti
    wrote on last edited by Ahti
    #1

    Hi
    I am trying to call a c++ method from a qml but I am not able to do so because of the error: undefined reference to 'vtable for Example'.

    My Code:

    example.h

    class Example: public QObject
    {
        Q_OBJECT
        public:
    
            explicit Example(QObject *parent = 0);      
            Q_INVOKABLE bool example_method(int );
    }
    

    example.cpp

    Example::Example(QObject *parent) : QObject(parent) {}
    bool Example::example_method() { ... }
    

    main.cpp

    int main() {
        ...
        Example adjust;
        engine.rootContext()->setContextProperty("example", &example);
        ...
    }
    

    main.qml

    Slider {
           ...
           onValueChanged: {
                 example.example_method(value)
          }
    }
    

    Please help how to fix this problem ?

    what is a signature ?? Lol

    1 Reply Last reply
    0
    • N Offline
      N Offline
      Nifiro
      wrote on last edited by
      #2
      class Example : public QObject
      {
          Q_OBJECT
          public:
              explicit Example(QObject *parent = 0);      
              Q_INVOKABLE bool example_method(int );
              virtual ~Example() override {}
      }
      
      AhtiA 1 Reply Last reply
      0
      • N Nifiro
        class Example : public QObject
        {
            Q_OBJECT
            public:
                explicit Example(QObject *parent = 0);      
                Q_INVOKABLE bool example_method(int );
                virtual ~Example() override {}
        }
        
        AhtiA Offline
        AhtiA Offline
        Ahti
        wrote on last edited by
        #3

        @Nifiro Still the same error.

        what is a signature ?? Lol

        KroMignonK 1 Reply Last reply
        0
        • AhtiA Ahti

          @Nifiro Still the same error.

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #4

          @Ahti Do you have tried to call qmake and rebuild the project?

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          AhtiA 1 Reply Last reply
          3
          • KroMignonK KroMignon

            @Ahti Do you have tried to call qmake and rebuild the project?

            AhtiA Offline
            AhtiA Offline
            Ahti
            wrote on last edited by
            #5

            @KroMignon How to do it ? both ? I am a newbie to qt

            what is a signature ?? Lol

            mrjjM 1 Reply Last reply
            0
            • AhtiA Ahti

              @KroMignon How to do it ? both ? I am a newbie to qt

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @Ahti
              alt text

              or to really clean it,
              alt text
              and delete the build folder

              AhtiA 1 Reply Last reply
              5
              • mrjjM mrjj

                @Ahti
                alt text

                or to really clean it,
                alt text
                and delete the build folder

                AhtiA Offline
                AhtiA Offline
                Ahti
                wrote on last edited by
                #7

                @mrjj Thanks I simple deleted the built and hit re-built and it worked thanks again :)

                what is a signature ?? Lol

                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