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. Get undefined reference error but don't know why
QtWS25 Last Chance

Get undefined reference error but don't know why

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.8k Views
  • 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
    casisto
    wrote on 21 Mar 2015, 12:16 last edited by p3c0
    #1

    Hello there,

    I have code a experimental minimal QApp to test how to open new Windows after pushing a button. But i get the error
    "undefined reference to 'vtable for MainWindow'".

    Here my SourceCode:
    mainwindow.h

    #pragma once
    #include <QWidget>
    #include <QBoxLayout>
    #include <QPushButton>
    #include "newwindow.h"
    
    class MainWindow : public QWidget
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = 0);
    
    public slots:
        void openNewWindow();
    };
    

    newwindow.h

    #pragma once
    
    #include <QWidget>
    #include <QBoxLayout>
    #include <QLabel>
    
    class NewWindow : public QWidget
    {
    public:
        NewWindow(QWidget *parent = 0);
    };
    

    mainwindow.cpp

    #include "mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) : QWidget(parent)
    {
        QVBoxLayout *vbox = new QVBoxLayout;
            vbox->setMargin(20);
        QPushButton *btn= new QPushButton("New window", this);
            btn->setMinimumSize(QSize(200,50));
    
        vbox->addWidget(btn, 2, Qt::AlignVCenter);
        setLayout(vbox);
    
        connect(btn, SIGNAL(clicked()), this, SLOT(openNewWindow()));
    }
    void MainWindow::openNewWindow()
    {
        NewWindow *newwindow = new NewWindow();
        newwindow->show();
    }
    

    newwindow.cpp

    #include "newwindow.h"
    
    NewWindow::NewWindow(QWidget *parent) : QWidget(parent)
    {
        QVBoxLayout *vbox = new QVBoxLayout;
            vbox->setMargin(20);
        QLabel *label = new QLabel("New Window", this);
    
        vbox->addWidget(label, 2, Qt::AlignVCenter);
        setLayout(vbox);
    }
    

    main.cpp

    #include "mainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow window;
        window.show();
        return a.exec();
    }
    

    Thanks for all they want help
    -Casisto

    Edited: Put code after 3 backticks(```) and end with the same - p3c0

    1 Reply Last reply
    0
    • C Offline
      C Offline
      casisto
      wrote on 21 Mar 2015, 12:30 last edited by
      #2

      ok,
      i had can solve it by myself.

      For all they have they problem too:

      The error is sourced from the use of "Q_OBJECT".
      To solve the error, right-cklick on the Project and choose "Run qmake" and after this: "Rebuild".

      Then the error should be disappeared ;-)

      -casisto

      1 Reply Last reply
      2
      • J Offline
        J Offline
        JKSH
        Moderators
        wrote on 21 Mar 2015, 12:47 last edited by
        #3

        Hi @casisto, I'm glad to hear that you've solved your problem. Thanks for sharing your solution!

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0
        • P Offline
          P Offline
          panoramix
          wrote on 21 Mar 2015, 14:21 last edited by
          #4

          I've also had the same problem that I solved the same way.
          I happened on Windows and ever on Linux

          1 Reply Last reply
          0

          3/4

          21 Mar 2015, 12:47

          • Login

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