Results 1 to 4 of 4

Thread: Question regarding QT ui

  1. #1

    Default Question regarding QT ui

    Hello I am making a program for work using Mainwindow... from that window I have several QDialogs.. one of the dialogs signal/slots is suppose to add items to a QTreeWidget that is located on ui Mainwindow... however i cannot get to access the QTreewidget from the dialog.cpp so I cannot modify anything... I ve tried inheritance and different things but it doesn't seem to work... any ideas on how to approach this??

    thank you!!!!!!!

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Question regarding QT ui

    One solution is to work with signals and slots.

    Create a slot slotNewItemsToAdd(list of items) in your mainwindow
    And create a signal newItemsToAdd(list of items) in your dialog.
    Connect them and that should be it.

    You do need to add your custom types to the moc though.
    If you need help with that, ask
    Last edited by tbscope; 5th June 2010 at 18:13. Reason: correct error

  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Question regarding QT ui

    Although there aren't any hard and fast rules about such things, I normally discourage cross-talk between GUI components as much as possible, In a case like this, I would store the dialog's settings in the dialog itself, then extract them if the user accepts the dialog, ignoring them if the user rejects it. Having various GUI objects changing others can lead to a logic and maintenance snarl that's difficult to recover from. It's best to let a central widget (like the main application) handle all such changes, and pass them along to the appropriate components.

    There are obviously times when direct manipulation makes sense. But they're normally rare, and when I find myself beginning to allow such communication, I take it as a signal that I'm doing something wrong, and need to rethink my approach to the problem.

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question regarding QT ui

    I completely agree with SixDegrees. Objects should be as encapsulated as is practical. There is very rarely a need for one form to access another forms UI elements, which is why they are private by default.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.