It should be said that I carefully googled and tried many ways, but the problem did not disappear. Here is the actual code, all in one main.cpp file, as it is conceived, when you press a button, it is separated into a new window.
#include <QApplication> #include <QtWidgets> class custombtn: public QPushButton{ Q_OBJECT public: custombtn(QWidget * parent = nullptr):QPushButton(parent){} public slots: void slotChangeParent(){ this->setParent(nullptr); this->show(); } }; int main(int argc, char **argv){ QApplication app(argc,argv); QWidget wgt; custombtn btn(&wgt); QLabel lbl("LABEL",&wgt); btn.resize(300,300); lbl.resize(300,100); btn.show(); lbl.show(); wgt.show(); QObject::connect(&btn, SIGNAL(clicked(bool)), &btn, SLOT(slotChangeParent())); return app.exec(); }
Here is the pro file:
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = untitled TEMPLATE = app SOURCES += main.cpp
I tried to run qmake, create a new project and build in it, delete the Debug folder and re-compile, the path to the project consists only of English letters, tried to copy the project even to the root of the disk (to make sure that it’s not the paths), but errors from the series LNK2001: неразрешенный внешний символ "public: virtual struct QMetaObject const* __cdecl custombrn::metaObject(void)const"[...]
remained. What can be wrong?
#include "main.moc"
- Pavel Parshin