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. How to copy a form class
Forum Updated to NodeBB v4.3 + New Features

How to copy a form class

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 283 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.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by
    #1
    wCellTypeInfo* temp = new wCellTypeInfo(m_pModelInfo, m_pParentWidget);
    	wSetupBaseBckg dlg(temp, m_pParentWidget);
    	{
    		m_pCellTypeInfo = temp;
    
    		if (dlg.DlgResult() == CollectEnums::MeasureMode_Settings::Apply)
    		{
    			/*wPhotoMetric_Settings* w = qobject_cast<wPhotoMetric_Settings*>(dlg.GetWidget());
    			if (w->IsChanged())
    				UpdateMesureInfo();
    
    			this->m_pChart->EnableMarkers(m_pPhometricInfo->bPVDisplay);*/
    		}
    

    When exiting the function, the wCellTypeInfo* temp variable is destroyed.
    Although it was copied with the assignment operator before being destroyed, the copied class is also destroyed because temp itself is destroyed. Is there any way to copy the form class itself?

    I made a deepcopy, but it doesn't copy the information in the UI

    void wCellTypeInfo::DeepCopy(const wCellTypeInfo* copy)
    {
    	ui					= copy->ui;
    	m_nChkCnt			= copy->m_nChkCnt;
    	m_pModelInfo		= copy->m_pModelInfo;
    	m_nSeletedCell		= copy->m_nSeletedCell;
    	m_pBtnGroup			= copy->m_pBtnGroup;
    	//m_pParentWidget		= copy.m_pParentWidget;
    }
    
    Christian EhrlicherC jsulmJ 2 Replies Last reply
    0
    • I IknowQT
      wCellTypeInfo* temp = new wCellTypeInfo(m_pModelInfo, m_pParentWidget);
      	wSetupBaseBckg dlg(temp, m_pParentWidget);
      	{
      		m_pCellTypeInfo = temp;
      
      		if (dlg.DlgResult() == CollectEnums::MeasureMode_Settings::Apply)
      		{
      			/*wPhotoMetric_Settings* w = qobject_cast<wPhotoMetric_Settings*>(dlg.GetWidget());
      			if (w->IsChanged())
      				UpdateMesureInfo();
      
      			this->m_pChart->EnableMarkers(m_pPhometricInfo->bPVDisplay);*/
      		}
      

      When exiting the function, the wCellTypeInfo* temp variable is destroyed.
      Although it was copied with the assignment operator before being destroyed, the copied class is also destroyed because temp itself is destroyed. Is there any way to copy the form class itself?

      I made a deepcopy, but it doesn't copy the information in the UI

      void wCellTypeInfo::DeepCopy(const wCellTypeInfo* copy)
      {
      	ui					= copy->ui;
      	m_nChkCnt			= copy->m_nChkCnt;
      	m_pModelInfo		= copy->m_pModelInfo;
      	m_nSeletedCell		= copy->m_nSeletedCell;
      	m_pBtnGroup			= copy->m_pBtnGroup;
      	//m_pParentWidget		= copy.m_pParentWidget;
      }
      
      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      @IknowQT said in How to copy a form class:

      Although it was copied with the assignment operator before being destroyed, the copied class is also destroyed because temp itself is destroyed. Is there any way to copy the form class itself?

      Maybe because wSetupBaseBckg deletes it in it's dtor.
      Simply create a new instance of temp if you need another one.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • I IknowQT
        wCellTypeInfo* temp = new wCellTypeInfo(m_pModelInfo, m_pParentWidget);
        	wSetupBaseBckg dlg(temp, m_pParentWidget);
        	{
        		m_pCellTypeInfo = temp;
        
        		if (dlg.DlgResult() == CollectEnums::MeasureMode_Settings::Apply)
        		{
        			/*wPhotoMetric_Settings* w = qobject_cast<wPhotoMetric_Settings*>(dlg.GetWidget());
        			if (w->IsChanged())
        				UpdateMesureInfo();
        
        			this->m_pChart->EnableMarkers(m_pPhometricInfo->bPVDisplay);*/
        		}
        

        When exiting the function, the wCellTypeInfo* temp variable is destroyed.
        Although it was copied with the assignment operator before being destroyed, the copied class is also destroyed because temp itself is destroyed. Is there any way to copy the form class itself?

        I made a deepcopy, but it doesn't copy the information in the UI

        void wCellTypeInfo::DeepCopy(const wCellTypeInfo* copy)
        {
        	ui					= copy->ui;
        	m_nChkCnt			= copy->m_nChkCnt;
        	m_pModelInfo		= copy->m_pModelInfo;
        	m_nSeletedCell		= copy->m_nSeletedCell;
        	m_pBtnGroup			= copy->m_pBtnGroup;
        	//m_pParentWidget		= copy.m_pParentWidget;
        }
        
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @IknowQT said in How to copy a form class:

        When exiting the function, the wCellTypeInfo* temp variable is destroyed

        Where is it destroyed?
        I don't see any delete in the code you posted.

        You can't copy QObject based classes in Qt. The only thing you can copy is the pointer, but then it is NOT a deep copy...

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

        I 1 Reply Last reply
        2
        • jsulmJ jsulm

          @IknowQT said in How to copy a form class:

          When exiting the function, the wCellTypeInfo* temp variable is destroyed

          Where is it destroyed?
          I don't see any delete in the code you posted.

          You can't copy QObject based classes in Qt. The only thing you can copy is the pointer, but then it is NOT a deep copy...

          I Offline
          I Offline
          IknowQT
          wrote on last edited by
          #4

          @jsulm
          @Christian Ehrlicher

          Thanks for the reply. I'll have to think about if there is another way.

          1 Reply Last reply
          0

          • Login

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