[Qt-interest] How to close s subwindow?

donglongchao donglongchao at 163.com
Wed Nov 11 04:50:27 CET 2009


在2009-11-11,"Louai Al-Khanji" <louai.khanji at gmail.com> 写道:
>On Tue, Nov 10, 2009 at 9:55 AM, donglongchao <donglongchao at 163.com> wrote:
>> 在2009-11-10,"John McClurkin" <jwm at nei.nih.gov> 写道:
>>>donglongchao wrote:
>>>> Hi,all
>>>>
>>>> I have a problem when I develop a MDI app whose UI was create by QT
>>>> Designer.The two subwindows of MdiArea were created by right-click on
>>>> MdiArea widget and then choose "add subwindow" from the pop menu.When I
>>>> start the app,both of the two subwindows appears,but I just want one of
>>>> them to appears.So I find two function called void *closeActiveSubWindow
>>>> <http://doc.trolltech.com/4.5/qmdiarea.html#closeActiveSubWindow>* ()
>>>> and void *closeAllSubWindows
>>>> http://doc.trolltech.com/4.5/qmdiarea.html#closeAllSubWindows>* ().But
>>>> neither of them is what I need.I just want a function who can close some
>>>> certain subwindow I want to close. Is there any function like that ,but
>>>> I missed somewhere?
>>>
>>>If closeActiveSubWindow() or closeAllSubWindows() won't work for you,
>>>you will have to write your own function that iterates over all the
>>>subwindow to find the one you want to close.
>>
>> It is not a good news for me.:-(.Maybe I should suggestion the developers of
>> QT to add some function like that.:-)
>>>Or I could reach my goal(start the app with only one
>>>> subwindow appears) through other better way?Any suggestions are welcomed.
>>>
>>>You can write your app so that only one subwindow appears on startup.
>>>You can also write your app so that no subwindows appear on startup.
>>>Whether a subwindow is shown depends on whether you call show() on the
>>>object.
>>>
>>
>> If you add subwindows by QT Designer as I descributed above(right
>> click,choose add subwindow..etc),you would get all your subwindows appears
>> when your app start.Because there will be a line of code says
>> "mdiAero->addSubwindow(xxx)" in the generated head file named ui_xxx.h which
>> will show all the subwindows.Unfortunately we could not modify the ui_xxx.h
>> file by hand and I did not find some property to set in QT Designer to
>> determine which subwindow should appear and which one should not ,too.I also
>> tried the hide() function.But I can only hide the widgets on the subwindow
>> but not the subwindow itself.I got a blank subwindow left.:-(.I think the
>> only way is remove the subwindows from mdiArea in order to let them
>> disappears.If this methond is not conventence,I have to setup my subwindows
>> in different .ui files but not intergrate them together in one big .ui file
>> like I am doing now.
>>
>> Any way,thank you for your suggestions,John McClurkin.
>>>> Thanks a lot in advance.
>>>>
>>>> Longchao
>>>>
>>>>
>
>I played with this for a while. The parent widget of the subwindow
>widget can be hidden. So if you add a subwindow called "subwindow1" in
>the designer, you can do this:
>
>ui.subwindow1->parentWidget()->hide();
>
>It's ugly, but the API doesn't seem to provide a clean way to do this.
>

Another question is that, in this case,when I click the close button of the subwindow,all the widgets in the subwindow and the subwindow itself will be deleted and all the pointer of them will became dangling pointers.Is it right? But I still have a signal should be received and exec by them from another thread.So when I click the close button,my app crash as the result of a segmentation fault(caused by tring to access a released invalid memory).So I want to know if there is some property to set so that I can let the subwindow to hide itself ,not delete it.If not,I think I have to write some code like ui.subwindow1->parentWidget()->hide() to handle the "close" signal of the subwindows to do that.It seems very ugly to do like this.Maybe I did not make a good design of my app.So any suggestion is appreciated.
Thanks a lot in advance.
>-- 
>- Louai Al-Khanji
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091111/f7ee49b0/attachment.html 


More information about the Qt-interest-old mailing list