Results 1 to 7 of 7

Thread: C++/QT Design

  1. #1

    Default C++/QT Design

    Hi, hoping to get some help re. code design.
    I've been codeing on and off for a few years now, started with HTML, Javascript, PHP then moved onto C, C++. Also dabbled in VB and Delphi. Just so you know where I'm kind of up to I know all the basics of C++ and have a basic understanding of encapsulation, polymorphism etc but I'm still struggling a bit getting everything sorted in my head where I don't have to stop and think about it before I do something.

    So anyway my issue is really with OOP I guess and how to organise my code accross multiple files. I'm at the stage where I want to start doing larger projects but just never sure of the correct way to do things. I should mention I'm using QTCreator for UI design and codeing.

    eg. If I have a project consisting of a widget stack, maybe 5-10 pages, each interacting with each other and drawing data from an SQlite database. SO I have files MyWindow.ui, MyWIndow.cpp, MyWindow.h and I have the MyWindow class.

    Should I -
    - keep each page of the widget stacks code to it's own .cpp and header files. ie a page_1_class.cpp, page_1_class each with it's own class. If so what is the best way to access the base class which is the class all the widgets belong to.

    - keep all the pages code in the base class (declare all my functions etc in the base header file) and just put the definitions in there own .cpp files.

    - keep all the QT related things (anything that directly interacts with a QWidget) to the base class and just farm out the data manipulation stuff.

    - Is it acceptable to create individual widget projects for each page and then just add these projects to the widget stack on a mainwindow.

    Any help or push in the right direction appreciated.
    Cheers

  2. #2
    Join Date
    Mar 2009
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: C++/QT Design

    I also have interest in this topic.
    Anyone can help us?

  3. #3
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: C++/QT Design

    My personal opinion and I do this for all my projects. I put all my classes in their own .h/.cpp no matter how big or some, or convience. Because when the classes grow and you stop adding more classes, it's a pain to scroll through it and nitpick at it.

    And by having them in their own, I know exactly where to go and easily add/modify them. I also put all my function in alphabetic order.

    I but it functions in visibility order:

    public:
    protected:
    private:

    And a-z in their own section. And seperate the functions from the variables. But now I'm using pimpl to keep my classes in BC mode.
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

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

    Default Re: C++/QT Design

    I totally agree with ComaWhite: One class one pair of cpp/h files. Alphabetical order of the function is nice, but since my editor as a good outlining windows, I am too lazy to to so

    But I you struggle how exactly organize your code, just have a look how others keep their code. Look for example at the projects of KDE (kate, dolphin, etc). Thay have a good code design with an standard.

  5. #5

    Default Re: C++/QT Design

    Thanks for the reply's.

    I think your right, I need to study some code by people who know what they're doing. I'll have a look and see how I go .

    Thanks again.

  6. #6
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: C++/QT Design

    You can click on my project link in the bottom and see mine. You have to click more at the top and go to my git repo, be sure to look at the experimental branch. Since its the one I'm working in right now
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  7. #7

    Default Re: C++/QT Design

    Thanks again for the help,
    I checked out some various app's/projects incuding yours ComaWhite and it's all starting to come together. I was struggling with organisation which browsing through other code really helped with.
    My other main problem was, I think I was still in procedural mode and even though I've understood the concepts of OOP for quite a while I wasn't really applying it appropriately. This coupled with a lack of organisation in my code meant once a project started to grow I was getting lost in my own code.
    I've had a couple "AHA" moments now though after seeing how others do things, going back over some basics and just coding some small projects and concentrating on making sure I utilise objects properly and more than I was.

    Cheers
    Xmeister

Similar Threads

  1. Replies: 3
    Last Post: 5th October 2008, 23:41
  2. Multiplatform Video Viewer Application Design Options
    By PhilippB in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2008, 09:38
  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. Design problem/question
    By Valheru in forum Qt Programming
    Replies: 2
    Last Post: 27th September 2006, 21:45
  5. 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.