Important: Please read the Qt Code of Conduct -

Counter example for slot and signal is not working (symbol(s) not found for architecture x86_64)

  • I'm trying to run the Counter example in this link but I get linker error. This is I've done
    @QT += core
    QT -= gui
    CONFIG -= app_bundle
    TEMPLATE = app
    TARGET = test
    SOURCES += main.cpp


    @#include <QtCore>
    #include <QVector>
    #include <QObject>

    class Counter : public QObject

    Counter() { m_value = 0; }

    int value() const { return m_value; }

    public slots:
    void setValue(int value);

    void valueChanged(int newValue);

    int m_value;

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

    int main()
    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 0;

    in the terminal

    @> qmake -makefile

    make @

    I got this error

    @/Applications/ -c -pipe -O2 -isysroot /Applications/ -mmacosx-version-min=10.6 -Wall -W -fPIE -DQT_NO_DEBUG -DQT_CORE_LIB -I../../Qt5.2.1/5.2.1/clang_64/mkspecs/macx-clang -I. -I../../Qt5.2.1/5.2.1/clang_64/lib/QtCore.framework/Versions/5/Headers -I. -F/Users/bandarhd/Qt5.2.1/5.2.1/clang_64/lib -o main.o main.cpp
    /Applications/ -headerpad_max_install_names -Wl,-syslibroot,/Applications/ -mmacosx-version-min=10.6 -o test main.o -F/Users/bandarhd/Qt5.2.1/5.2.1/clang_64/lib -framework QtCore
    Undefined symbols for architecture x86_64:
    "Counter::valueChanged(int)", referenced from:
    Counter::setValue(int) in main.o
    _main in main.o
    "Counter::staticMetaObject", referenced from:
    _main in main.o
    "vtable for Counter", referenced from:
    _main in main.o
    NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [test] Error 1

    I'm using
    @Mac OS X 10.9.4
    QMake version 3.0
    Using Qt version 5.2.1 in /Users/XXX/Qt5.2.1/5.2.1/clang_64/lib@

  • Lifetime Qt Champion


    It's not a full featured example, these are code snippets to illustrate the theory of Signals and Slots.

    You should rather take a look at the various full examples like the Calculator example which has code and explanation.

  • Hi,

    This might help you and this is how you can use your signal to connect to your slot.

    @QObject::connect(&a, SIGNAL(valueChanged(int)),&b,SLOT(setValue(int)));@

    [edit: added missing coding tags @ SGaist]

  • Lifetime Qt Champion

    The example is showing the new notation.

    However the code snippets don't constitute a full example.

Log in to reply