‘CGUI::CGUI(const CGUI&)’ is implicitly deleted because the default definition would be ill-formed:
-
../src/Main.cpp: In function ‘int main(int, char**)’:
../src/Main.cpp:15:20: error: use of deleted function ‘CGUI::CGUI(const CGUI&)’
15 | CGUI myapp = CGUI();
| ^
In file included from ../src/Main.cpp:9:
../src/CGUI.h:25:7: note: ‘CGUI::CGUI(const CGUI&)’ is implicitly deleted because the default definition would be ill-formed:
25 | class CGUI : public QMainWindow
| ^~~~
../src/CGUI.h:25:7: error: ‘QMainWindow::QMainWindow(const QMainWindow&)’ is private within this contextit fails because it was compiler deleted. why?
main.cpp
#include "CGUI.h" int main(int argc, char **argv) { std::cout << "__name__"; QApplication app (argc, argv); CGUI myapp = CGUI(); myapp.show(); return app.exec(); }
CGUI.h
#ifndef CGUI_H_ #define CGUI_H_ #include <QMainWindow> #include <QSerialPort> #include <string> #include <cstring> #include <iostream> #include <fstream> #include <cmath> #include <thread> #include <unistd.h> #include <sstream> #include <QtGui> #include <QApplication> #include <functional> class CGUI : public QMainWindow { public: CGUI(QWidget *parent = 0); virtual ~CGUI(); }; #endif /* CGUI_H_ */
CGUI.cpp
CGUI::CGUI(QWidget *parent): QMainWindow(parent) { // TODO Auto-generated constructor stub } CGUI::~CGUI() { // TODO Auto-generated destructor stub }
ok. stripped down basic
i did not add "Q_OBJECT", which i was told to add, then told not to add.
using linux, eclipse -
../src/Main.cpp: In function ‘int main(int, char**)’:
../src/Main.cpp:15:20: error: use of deleted function ‘CGUI::CGUI(const CGUI&)’
15 | CGUI myapp = CGUI();
| ^
In file included from ../src/Main.cpp:9:
../src/CGUI.h:25:7: note: ‘CGUI::CGUI(const CGUI&)’ is implicitly deleted because the default definition would be ill-formed:
25 | class CGUI : public QMainWindow
| ^~~~
../src/CGUI.h:25:7: error: ‘QMainWindow::QMainWindow(const QMainWindow&)’ is private within this contextit fails because it was compiler deleted. why?
main.cpp
#include "CGUI.h" int main(int argc, char **argv) { std::cout << "__name__"; QApplication app (argc, argv); CGUI myapp = CGUI(); myapp.show(); return app.exec(); }
CGUI.h
#ifndef CGUI_H_ #define CGUI_H_ #include <QMainWindow> #include <QSerialPort> #include <string> #include <cstring> #include <iostream> #include <fstream> #include <cmath> #include <thread> #include <unistd.h> #include <sstream> #include <QtGui> #include <QApplication> #include <functional> class CGUI : public QMainWindow { public: CGUI(QWidget *parent = 0); virtual ~CGUI(); }; #endif /* CGUI_H_ */
CGUI.cpp
CGUI::CGUI(QWidget *parent): QMainWindow(parent) { // TODO Auto-generated constructor stub } CGUI::~CGUI() { // TODO Auto-generated destructor stub }
ok. stripped down basic
i did not add "Q_OBJECT", which i was told to add, then told not to add.
using linux, eclipse@micha_eleric said in ‘CGUI::CGUI(const CGUI&)’ is implicitly deleted because the default definition would be ill-formed::
CGUI myapp = CGUI();
This should be simply
CGUI myapp;
With your current code you're creating a CGUI (with CGUI()) and assign it to another one. This means the first one is copied and QObjects cannot be copied.
-
@micha_eleric said in ‘CGUI::CGUI(const CGUI&)’ is implicitly deleted because the default definition would be ill-formed::
CGUI myapp = CGUI();
This should be simply
CGUI myapp;
With your current code you're creating a CGUI (with CGUI()) and assign it to another one. This means the first one is copied and QObjects cannot be copied.
@jsulm ty, that explains other people stating QObjects cannot be copied