Results 1 to 9 of 9

Thread: [Qt Creator] Coding style.[Help]

  1. #1
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default [Qt Creator] Coding style.[Help]

    Hey guys,here I'm again with some questions!

    Well,I have been reading the "C++ GUI with Qt" book and it's not too hard.
    I understand the most parts of the code...

    But when I don't use the book and try to code something small myself(like a calculator),I have difficulties in 1)where to put specific parts of the code(like:i know that i will put decleration in a .h file and definition in .cpp,but I get confused when it becomes complicated..),are there any rules about what to put where?

    2)And one more thing:As I understood,for each new widget/dialog/window i make I have to make 2 new files(.h & .cpp for it)as well,right?

    Thank you and please explain if possible where different parts of the code should go!

  2. #2
    Join Date
    Oct 2010
    Posts
    55
    Thanks
    1
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    9

    Default Re: [Qt Creator] Coding style.[Help]

    These questions are more related to C++ in general, and not so much to Qt/Qt Creator really, but that's ok anyway.

    Like you said; typically when you create a new class, you create a header file (.h) containing the class/function declarations + data members, and a C++ file (.cpp) containing the body of each function (their definitions). It is more or less standard practice to have one class declaration per header file and its definitions in a corresponding source file, but it is not strictly required. For example, it is common to find smaller helper objects grouped together in the same file with other objects.

    You can also place the implementation of a function in the header file itself (you see it in a lot of examples and tutorials) -- and many times it is perfectly valid to do so, e.g., short getters and setters in the header is common and in the case of template classes, it is actually the only way to do it (simplified statement, but anyway...). However, as classes get longer and more complicated, it is generally a good idea to try to do as much "code separation" as possible.

    Not sure if that was of any help to you.
    Last edited by helloworld; 6th February 2011 at 18:08.

  3. #3
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [Qt Creator] Coding style.[Help]

    Quote Originally Posted by "BumbleBee" View Post
    Hey guys,here I'm again with some questions!

    Well,I have been reading the "C++ GUI with Qt" book and it's not too hard.
    I understand the most parts of the code...
    You have started reading that book too early. Take a good C++ book first. Then make a mid size simple program in C++. Come back to this book.

  4. #4
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: [Qt Creator] Coding style.[Help]

    [B]helloworld[B]:Yeah,that was nice.I got what you mean.thnx
    nish:Hey man,what is the point in doing so?
    Do you think my question relies on C++ experience?I don't think so,because Qt does have different tecniques!

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [Qt Creator] Coding style.[Help]

    Quote Originally Posted by "BumbleBee" View Post
    nish:Hey man,what is the point in doing so?
    Do you think my question relies on C++ experience?I don't think so,because Qt does have different tecniques!
    No, you are completely wrong. Qt "inherits" everything from C++ as you are using C++ to code with Qt. Qt doesn't have any "different techniques". So to refer to your original question - you don't need to have a .h and a .cpp file for a new widget, you don't need to put any declarations in any .h files nor anything like that. You need to follow rules defined by your C++ compiler that is compliant with the C++ standard. You need to familiarize yourself with C++ before doing anything serious with Qt, otherwise you'll end up where you are now - as soon as you step beyond some book or tutorial, you won't know where to go next. Also remember that C++ is also just a tool, just like Qt. You need something more to be a programmer than to learn C++ syntax. This is exactly the same for any other programming language. So after a C++ book I'd recommend some book or course about programming as such. Learning how computers work internally is also a good thing to do.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: [Qt Creator] Coding style.[Help]

    But what do you mean familiarize myself with C++?
    Do I have to code code/read everything to move on?
    Well,I think that all the things I know are enough..and others hae told me that it's ok.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [Qt Creator] Coding style.[Help]

    Quote Originally Posted by "BumbleBee" View Post
    But what do you mean familiarize myself with C++?
    I mean to understand why and how things work with C++. For instance why you declare things on heap and not on stack and what consequences it has. Or what are the weaknesses of exceptions in C++. Or what exactly happens if you don't implement your own constructor/destructor/copy constructor/assignment operator for a class. Things like that. Then it comes to the process of building an application - what exactly happens to the source code until it becomes the final binary you can execute.

    Well,I think that all the things I know are enough..and others hae told me that it's ok.
    If you are asking the things you are asking then you probably don't know enough.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: [Qt Creator] Coding style.[Help]

    Quote Originally Posted by "BumbleBee" View Post
    But what do you mean familiarize myself with C++?
    He means you need to learn C++.

  9. #9
    Join Date
    Sep 2011
    Posts
    21
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: [Qt Creator] Coding style.[Help]

    Back to Coding Style...

    Right now... LEARN...

    Get it to work, first. Worry about "Style" later.

    *IF* you were in a commercial setting your company will probably cite a Style Document or have one of their own.

    But, at this point you are too far down on the learning curve to worry about style, as such.

    Now, Syntax... That's a different animal altogether...

Similar Threads

  1. Coding Style for object (this)
    By MIH1406 in forum General Programming
    Replies: 18
    Last Post: 18th September 2009, 10:32
  2. coding style
    By mickey in forum General Discussion
    Replies: 2
    Last Post: 16th March 2008, 19:19
  3. Qt specific questions regaring coding style
    By Raistlin in forum Qt Programming
    Replies: 4
    Last Post: 26th February 2007, 10:14
  4. Coding style about pointer
    By vql in forum General Programming
    Replies: 4
    Last Post: 5th February 2007, 09:07
  5. What is your coding style ??
    By guestgulkan in forum General Discussion
    Replies: 9
    Last Post: 29th May 2006, 10:22

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.