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. [SOLVED] Qt Visual Studio Add-in, Signal & Slots problems
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Qt Visual Studio Add-in, Signal & Slots problems

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 11.2k 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.
  • H Offline
    H Offline
    helloworld922
    wrote on last edited by
    #1

    I'm trying to compile the basic Qt signal and slots example given "here":http://qt-project.org/doc/qt-4.8/signalsandslots.html with the Visual Studio 2010 add-in (version 1.1.11), and it's giving me a bunch of link errors:

    bq. 1>main.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl Counter::metaObject(void)const " (?metaObject@Counter@@UEBAPEBUQMetaObject@@XZ)
    1>main.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl Counter::qt_metacast(char const *)" (?qt_metacast@Counter@@UEAAPEAXPEBD@Z)
    1>main.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl Counter::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Counter@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
    1>main.obj : error LNK2019: unresolved external symbol "protected: void __cdecl Counter::valueChanged(int)" (?valueChanged@Counter@@IEAAXH@Z) referenced in function "public: void __cdecl Counter::setValue(int)" (?setValue@Counter@@QEAAXH@Z)

    I looked around and it seems to indicate that the project isn't moc'ing correctly, however I'm not sure how to fix this.

    This is the code:

    @
    #include <QtCore/QCoreApplication>

    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[])
    {
    QCoreApplication a(argc, argv);
    Counter a1, a2;
    QObject::connect(&a1, SIGNAL(valueChanged(int)), &a2, SLOT(setValue(int)));

    return a.exec();
    }@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on last edited by
      #2

      You should add your class declaration in header(.h) file. In VS moc'ing is done only on .h files.
      P.S.: you can also add custom Build Step to .cpp files and include .moc in .cpp...

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        helloworld922
        wrote on last edited by
        #3

        thanks, that solved my problem.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AcerExtensa
          wrote on last edited by
          #4

          Please add "[SOLVED]" left to the topic subject.

          God is Real unless explicitly declared as Integer.

          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