Results 1 to 9 of 9

Thread: How to design Qt applications are better?

  1. #1
    Join Date
    Sep 2009
    Location
    Nanjing, China
    Posts
    46
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to design Qt applications are better?

    I found most Qt applications are extends QMainWindow class and there are lots of QAction instances. So my question is how to design these QActions? Most starts' books put them into QMainWindow's subclass derictly, but when this application gets bigger and bigger, it is rather difficult to manage them.

    Could you tell me how to design Qt applcations' code? Or some other suggestions? Or could you let me know some open source Qt applications' code to study? Don't tell me KDE because its code is so big that I hardly read it.

    Thank you all!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to design Qt applications are better?

    Quote Originally Posted by FinderCheng View Post
    I found most Qt applications are extends QMainWindow class and there are lots of QAction instances. So my question is how to design these QActions? Most starts' books put them into QMainWindow's subclass derictly, but when this application gets bigger and bigger, it is rather difficult to manage them.
    But somewhere you have to manage them. So a QMainWindow is the best place for it. There you also set the connections up. A way for better managing is that you declare two functions: initActions() where you set up all the actions and initConnections() where you establish all the connections. Move both functions to the bottom of your file, then you don't "see" them.

    Could you tell me how to design Qt applcations' code?
    Like any other C++ program. Have a look at the examples and tutorials which came with Qt.

    Or some other suggestions? Or could you let me know some open source Qt applications' code to study? Don't tell me KDE because its code is so big that I hardly read it.
    Try KDE But of course not the whole, just pick up one application and study its code. E.g. Konqueror.

  3. The following user says thank you to Lykurg for this useful post:

    FinderCheng (19th October 2009)

  4. #3
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: How to design Qt applications are better?

    I think it is a matter of personal taste.

    I agree with you that the QMainWindow subclass is a good candidate to become the good object of a QApplication.

    From the academic point of view, this is purely wrong because a window is a view class and should not contain any business logic code at all.

    I suggest to put most code in QObject-subclasses and let these objects provide actions that you can put around in your mainwindow. The downside of this approach is that you cannot do it with designer.

    An extra suggestion from me is to put most of your code in subclasses of QAbstractListModel or QAbstractTableModel if it somehow represents a list in any form, even if you will not it in a listview in the final gui. The nice thing about this is that you can attach a listview to it for debugging purposes instead of adding a lot of qDebug.
    It's nice to be important but it's more important to be nice.

  5. The following user says thank you to axeljaeger for this useful post:

    FinderCheng (19th October 2009)

  6. #4
    Join Date
    Sep 2009
    Location
    Nanjing, China
    Posts
    46
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to design Qt applications are better?

    Yeah, thank you all!
    I was a Qt starter from Java coder. People always say "make clear layer" so try not to add logical business code. As a result I wanted to create a class "ActionManager" to manage all QAction instances. But in C++ applications maybe there are different. So thank you all again!
    Any other suggestions? Thanks!

  7. #5
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: How to design Qt applications are better?

    What shall this action manager do? In the end, an action in Qt is a wrapper around either a property or a slot that adds a nice name and an icon. What do you want to manage there?
    It's nice to be important but it's more important to be nice.

  8. The following user says thank you to axeljaeger for this useful post:

    FinderCheng (19th October 2009)

  9. #6
    Join Date
    Sep 2009
    Location
    Nanjing, China
    Posts
    46
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to design Qt applications are better?

    I've no idea. I want to put all actions there, such as a map, the then it can get by its key. Then in this class all action connections are connected so simply gets out.

  10. #7
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: How to design Qt applications are better?

    So this class will have EVERY other class of your application as a dependency? Because it has to know all the objects that are receiving signals. This is not a very modular approach.
    It's nice to be important but it's more important to be nice.

  11. The following user says thank you to axeljaeger for this useful post:

    FinderCheng (19th October 2009)

  12. #8
    Join Date
    Sep 2009
    Location
    Nanjing, China
    Posts
    46
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to design Qt applications are better?

    Yes, it seems it has to know all classes who need to use QActions. So it may a friend class of these classes. It is not good design. Or you can make a lot of signals and slots between these classes, but I think this makes it too complex. So what's your opinion? Where should these QActions put? QMainWindow's subclass is a good place? I'd not quite follow your post hours ago.

  13. #9
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: How to design Qt applications are better?

    I would not put all QActions in a single place.

    ATM I'm developing an application that does light control.

    It has a number of components, for example the component that talks to the hardware. This component provides a QAction connectAction that I can use anywhere else. Because my hardware controller owns that QAction, it can uncheck it when I plug out my hardware.

    Let each component provide their actions and then use the mainwindow just to put the actions somewhere in the GUI.
    It's nice to be important but it's more important to be nice.

  14. The following user says thank you to axeljaeger for this useful post:

    FinderCheng (19th October 2009)

Similar Threads

  1. Replies: 3
    Last Post: 28th August 2009, 13:45
  2. Replies: 3
    Last Post: 5th October 2008, 23:41
  3. Need some help on design and implementation
    By cool_qt in forum Qt Programming
    Replies: 2
    Last Post: 30th July 2008, 21:19
  4. Dialog and code design issue
    By Gopala Krishna in forum Qt Programming
    Replies: 1
    Last Post: 24th September 2006, 17:54

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.