Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9114495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:12:49+00:00 2026-06-17T04:12:49+00:00

Possible Duplicate: Undefined reference to vtable. Trying to compile a Qt project here is

  • 0

Possible Duplicate:
Undefined reference to vtable. Trying to compile a Qt project

here is the code

#include <iostream>
#include <QApplication>
#include <QTimer>


class myClass : public QObject {
    Q_OBJECT

public:
    QTimer *timer;
    myClass(){
        timer = new QTimer(this);
        connect(timer, SIGNAL(timeout()), this, SLOT(mySlot()));
        timer->start(1000);
    }
public slots:
    void mySlot() {
        std::cout << "Fire" << std::endl;
    }
};

int main() {
    std::cout << "Hello, world";
    myClass atimer;
    return 0;
}

Apart from the error, there are two more things I don’t understand:

  1. Why there isn’t any semicolon after macros, in this case Q_OBJECT. It doesn’t seem to obey C++ syntax but yet people write code like that.

  2. The “public slots” is a modifier created by Qt, but how come gcc compiler can still understand it. How could an IDE like Qt modify the standard syntax of a language?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:12:52+00:00Added an answer on June 17, 2026 at 4:12 am

    You didn’t give the exact error message, but I suspect what’s happening is that you didn’t run moc on your code, or you didn’t compile the code generated by moc, or you didn’t link the code into your executable/library.

    As for your other questions:

    1. You don’t need to have a semicolon after macros; the preprocessor doesn’t care about semicolons – only the compiler does. So whether or not you need to add a semicolon manually depends on what your macro (Q_OBJECT) in this case expands to, and where you use it. In your case, no semicolon is needed.

    2. slots is an macro which expands to an emtpy string, so any C++ compile can process it. However, slots is also recognized as a special key word by moc. The same goes for signals, by the way (it’s a macro expanding to protected:).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Undefined reference to vtable I have a class Student on the file
Possible Duplicate: C++: undefined reference to static class member The following C++ code compiles
Possible Duplicate: Undefined reference to vtable Running the following code is causing a linker
Possible Duplicate: C++: undefined reference to static class member I'm using MinGW. Why static
Possible Duplicate: undefined reference to pthread_create in linux (c programming) I am trying to
Possible Duplicate: Resolving a linker error: undefined reference to static class members This declaration:
Possible Duplicate: Undefined symbols “vtable for …” and “typeinfo for…”? C++ Undefined Reference to
Possible Duplicate: GCC C++ Linker errors: Undefined reference to 'vtable for XXX', Undefined reference
Possible Duplicate: GCC C++ Linker errors: Undefined reference to 'vtable for XXX', Undefined reference
Possible Duplicate: g++ undefined reference to typeinfo Undefined symbols “vtable for …” and “typeinfo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.