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. ‘CGUI::CGUI(const CGUI&)’ is implicitly deleted because the default definition would be ill-formed:
QtWS25 Last Chance

‘CGUI::CGUI(const CGUI&)’ is implicitly deleted because the default definition would be ill-formed:

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 964 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.
  • M Offline
    M Offline
    micha_eleric
    wrote on 18 Feb 2022, 04:36 last edited by micha_eleric
    #1

    ../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 context

    it 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

    J 1 Reply Last reply 18 Feb 2022, 06:09
    0
    • M micha_eleric
      18 Feb 2022, 04:36

      ../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 context

      it 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

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 18 Feb 2022, 06:09 last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply 19 Feb 2022, 01:26
      1
      • J jsulm
        18 Feb 2022, 06:09

        @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.

        M Offline
        M Offline
        micha_eleric
        wrote on 19 Feb 2022, 01:26 last edited by
        #3

        @jsulm ty, that explains other people stating QObjects cannot be copied

        1 Reply Last reply
        0

        1/3

        18 Feb 2022, 04:36

        • Login

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