Get undefined reference error but don't know why
-
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
-CasistoEdited: Put code after 3 backticks(```) and end with the same - p3c0
-
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