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. Signal/Slot. Error during compilation.
Forum Updated to NodeBB v4.3 + New Features

Signal/Slot. Error during compilation.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.1k 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
    wf778899
    wrote on 20 Jul 2014, 11:40 last edited by
    #1

    Hi to all! Recently i have start to learn Qt and now i try to use signals and slots in a simple user widget taked from the example in Qt Assistance (listing below). But it can't build in, error messages are appears in lines 3, 6, 19, 27, 241 (its deskriptions are below the listing...). I uses Qt 5.3.1. Can anybody help me?
    @#include <QApplication>
    #include <QObject>
    class Counter : public QObject{
    Q_OBJECT
    public:
    Counter() { m_value = 0; }
    int value() const { return m_value; }
    public slots:
    void setValue(int value);
    signals:
    void valueChanged(int newValue);
    private:
    int m_value;
    };

    void Counter::setValue(int value) {
    if (value != m_value) {
    m_value = value;
    emit valueChanged(value);
    }
    }

    int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    Counter a, b;
    QObject::connect(&a, &Counter::valueChanged, &b, &Counter::setValue);
    a.setValue(12); // a.value() == 12, b.value() == 12
    b.setValue(48); // a.value() == 12, b.value() == 48
    return app.exec();
    }
    @

    Line 19 D:\Projects\QT\qqq\main.cpp:19: error: undefined reference to Counter::valueChanged(int)' Line 27 D:\Projects\QT\qqq\main.cpp:27: error: undefined reference to Counter::valueChanged(int)'
    Line 06 D:\Projects\QT\qqq\main.cpp:6: error: undefined reference to vtable for Counter' Line 241 C:\Qt\5.3\mingw482_32\include\QtCore\qobject.h:241: error: undefined reference to Counter::staticMetaObject'
    Line 03 D:\Projects\QT\qqq\main.cpp:3: error: undefined reference to `vtable for Counter'
    collect2.exe:-1: error: error: ld returned 1 exit status

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 20 Jul 2014, 12:02 last edited by
      #2

      Hi, welcome to devnet.

      MOC (the meta object compiler) reads only headers. Your class declaration (with Q_OBJECT macro) is in a .cpp file so it won't generate the QObject stuff (the undefined symbols you're getting).
      Put your class in a header where it belongs and it should compile fine.

      1 Reply Last reply
      0
      • W Offline
        W Offline
        wf778899
        wrote on 20 Jul 2014, 12:07 last edited by
        #3

        I had already guessed)) Fanks a lot for reply!)

        1 Reply Last reply
        0

        2/3

        20 Jul 2014, 12:02

        • Login

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