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. Counter example for slot and signal is not working (symbol(s) not found for architecture x86_64)
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.7k 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.
  • C Offline
    C Offline
    CroCo
    wrote on last edited by
    #1

    I'm trying to run the Counter example in this link http://doc.qt.io/qt-5/signalsandslots.html but I get linker error. This is I've done

    project.pro
    @QT += core
    QT -= gui
    CONFIG -= app_bundle
    TEMPLATE = app
    TARGET = test
    SOURCES += main.cpp
    @

    main.cpp

    @#include <QtCore>
    #include <QVector>
    #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()
    {
    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 project.pro

    make @

    I got this error

    @/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -O2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -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/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -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@

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Pradeep P NP Offline
        Pradeep P NP Offline
        Pradeep P N
        wrote on last edited by
        #3

        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]

        Pradeep Nimbalkar.
        Upvote the answer(s) that helped you to solve the issue...
        Keep code clean.

        1 Reply Last reply
        2
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The example is showing the new notation.

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

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