1. Parent questions
Say that inside my main window constructor I have the following code:
myWidget = new MyWidget(this);
myLayout = new MyLayout(this);
myLayout->addWidget(myWidget);
myWidget = new MyWidget(this);
myLayout = new MyLayout(this);
myLayout->addWidget(myWidget);
To copy to clipboard, switch view to plain text mode
If I understood the documention correctly layout becomes parent of every widget added to layout with addWidget method. So I could go with out this when I allocate memory for myWidget. I could have wrote myWidget = new MyWidget(). This is trivial example, but I have classes that have layout within layouts and 10 - 20 widget added to those layouts. Is it better practice not to give parents to widget when allocating memory for them and use addWidget methods to give them appropriate parent, or to give them some parent when I allocate memory for them and change the parent later when I have where to add them. Second approach maybe create an overhead but I am not sure which method is better? When I run my code from creator the second approach generate messages like widget already has parent. The first one does not.
2. Signals question
I have an application that have among other things two ComboBoxes. In one are clients and in other are jobs for the selected client. Every time current index in either of those ComboBoxes is changed signal is emited and one of two slots of my bussines logic class handles the signal. Application sometimes crashed I suspect because both functions change the state of my internal data structure, which in turn can cause currentIndex in one or both ComboBoxes to change which in turn emits the signals which in turn causes slot functions to be called while internal data structure is in transit and possibly error state. I am not sure if this is the cause but I added the following code in four methods that change my internal data structure and data in my widget. First method clears everything. Second initialize everything to starting values. Third and fourth are slots that handles the signals.
m_widget->blockSignals(true);
//do what ever method already did
m_widget->blockSignals(false);
m_widget->blockSignals(true);
//do what ever method already did
m_widget->blockSignals(false);
To copy to clipboard, switch view to plain text mode
Is this approach considered good programing practice using Qt or is there a better way?
3. Event question
Is there a way to make widget not respond to mouse wheel. People which are using my application are getting confused. For example ComboBox reacts if you scroll the mouse wheel while the pointer is above ComboBox even if you didn't clicked on the ComboBox first. When user clicks on one ComboBox makes a selection and just puts mouse pointer above another ComboBox and scroll the second ComboBox reacts and not the first. I want for start to ComboBox ignore mouse wheel. Later I would try to accomodate application to their wishes and make probably only clicked widget respond to mouse wheel but for start I just what a way to make specific widget ignore mouse wheel. I read the documentation but failed to find the way to do this. If you could point the way for me to a class, method, or a link where is described how to do this it would save me great deal of time.
Bookmarks