When copying throws an error
CMakeFiles/qthelloworld.dir/MyDialog.cpp.o: In function `MyDialog::MyDialog(QWidget*)': /home/ilia/CLionProjects/qthelloworld/qthelloworld/MyDialog.cpp:7: undefined reference to `vtable for MyDialog' /home/ilia/CLionProjects/qthelloworld/qthelloworld/MyDialog.cpp:7: undefined reference to `vtable for MyDialog' collect2: error: ld returned 1 exit status CMakeFiles/qthelloworld.dir/build.make:101: recipe for target 'qthelloworld' failed make[3]: *** [qthelloworld] Error 1 CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/qthelloworld.dir/all' failed make[2]: *** [CMakeFiles/qthelloworld.dir/all] Error 2 CMakeFiles/Makefile2:84: recipe for target 'CMakeFiles/qthelloworld.dir/rule' failed make[1]: *** [CMakeFiles/qthelloworld.dir/rule] Error 2 Makefile:118: recipe for target 'qthelloworld' failed make: *** [qthelloworld] Error 2 Trying to create a dialog box that says "Hello World".
Here is the main function
#include <QApplication> #include "MyDialog.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); MyDialog *dialog = new MyDialog; dialog->show(); return app.exec(); } In the original code, there are no backslashes in the import, I inserted it in order to show the imports themselves (mb in them is the case).
MyDialog.h file
#ifndef QTHELLOWORLD_MYDIALOG_H #define QTHELLOWORLD_MYDIALOG_H #include <QtWidgets/QVBoxLayout> #include <QLabel> #include <QPushButton> #include <QtWidgets/QDialog> class MyDialog: public QDialog { Q_OBJECT public: MyDialog(QWidget *parent = 0); }; #endif //QTHELLOWORLD_MYDIALOG_H MyDialog.cpp
#include "MyDialog.h" MyDialog::MyDialog(QWidget *parent) : QDialog(parent) { QVBoxLayout *layout = new QVBoxLayout(this); QLabel *lable = new QLabel(this); lable->setText("<font color = green> Hello, World! </font>"); QPushButton *button = new QPushButton(this); button->setText("close"); layout->addWidget(lable); layout->addWidget(button); connect(button, SIGNAL(clicked()), this, SLOT(close())); } I would be grateful if you say what the error is, why it is not compiled.
qmake. - AnT 6:08 pm