[Qt-interest] qResizeEvent problem

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Thu Mar 26 09:00:23 CET 2009


Hi Bijay, 
 
- Qt code can call resize on a widget due to layout, and in designer
generated code, and possibly other places.  You should avoid making
assumptions when handling events.  In this case, initialise the other
variables to NULL in the constructor, and test them in resizeEvent before
using them. 
 
- You are calling this->resize within the resizeEvent - and using the
existing size anyway! I am surprised you are not crashing with stack
overflow. 
 
- All you are doing is changing the size of several other widgets. This
should be done using layouts. Play with them in the designer until you get
an understanding of how to use them. Then you won't need the resizeEvent
override. 
 
- Which Qt example or demo did you use as the basis of your project? As a
rule of thumb, you will save a lot of time by looking for the example that
most closely matches your requirements, and copy that to start a new
project. Then you can ask on this group if there is anything in the example
that you don't understand. If there are other requirements, then merge their
examples progressively, and keep this initial prototype as a useful way of
quickly checking Qt compatibility when each version comes out. 
 
Hope that helps, 
 
Tony
 

-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Bijay Panda
Sent: Thursday, 26 March 2009 16:11
To: qt-interest at trolltech.com
Subject: [Qt-interest] qResizeEvent problem


Hi All,
In my project,I have a resizeEvent(QResizeEvent *e) method to resize the
GUI.
It should be excuted when ever user resizes the GUi, But control directly
goes to 
above method instead of executing other methods where i have created the GUI
first.
And inside resizeEvent()  i am resizing the widget without allocating
memory.So i am
 getting segmentation fault.No where i called this method.
Here is my code bellow..

void OMCSConsole::createMenuControls()
{

      cout<<"Inside MenuControl::" <<endl; 
                 
      cout<<"originalMainWindowWidth  :"<<originalMainWindowWidth<<endl;
      cout<<"originalMainWindowHeight :"<<originalMainWindowHeight<<endl;
     
     _MenuBarGroupBox = new QGroupBox(this);
     _MenuBarGroupBox->setGeometry(0,0,this->width()-5,32);
     _MenuBarGroupBox->show();
              
     _menuBarArea     = new QScrollArea(_MenuBarGroupBox);  
     _menuBarArea->setGeometry(0,1,_MenuBarGroupBox->width()-1,31);
     _menuBarArea->setFrameStyle(QFrame::NoFrame);
     
     _MenuBar = new MenuBar(_MenuBarGroupBox);
     _MenuBar->setGeometry(0,0,_MenuBarGroupBox->width()-1,31);
     _menuBarArea->setWidget(_MenuBar);
     _menuBarArea->show();
     _MenuBar->createMenuBar(this->width(),_MenuBarGroupBox->height());
//this->width()//
    }
   
void OMCSConsole::resizeEvent(QResizeEvent *event)
{
   
      cout<<"Inside Resize Event :"<<endl;
     
      resizedMainWindowWidth  = this->width();
      resizedMainWindowHeight = this->height();
      cout<<"resizedMainWindowWidth :"<<resizedMainWindowWidth<<endl;
      cout<<"resizedMainWindowHeight :"<<resizedMainWindowHeight<<endl;
      this->resize(resizedMainWindowWidth,resizedMainWindowHeight);
      
      cout<<"Resizing menuBarGrpBox."<<endl;
      //_MenuBarGroupBox->resize(1000,32);
     // cout<<"Crash after menuBarGrpBox."<<endl;
     
 
_MenuBarGroupBox->setGeometry(0,0,this->width()-5,32);//this->width()//menuB
ar
       
     _menuBarArea->setGeometry(0,1,_MenuBarGroupBox->width()-1,31);
    
        
     _MenuBar->setGeometry(0,0,_MenuBarGroupBox->width()-1,31);

}

Here it's showing crash immediately executing  this statement
 cout<<"Resizing menuBarGrpBox."<<endl;
I got stuck here.

Plz Plz any one help me out.

-- 
Thanks & Regards

Bijay .



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090326/d92ac2e7/attachment.html 


More information about the Qt-interest-old mailing list