Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Ask Help from beginner
Forum Updated to NodeBB v4.3 + New Features

Ask Help from beginner

Scheduled Pinned Locked Moved Language Bindings
4 Posts 4 Posters 4.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jorkax
    wrote on last edited by
    #1

    Hi everybody, I do not know if this is the right place to post my question.
    Anyway this is the issue.
    I am beginner Qt and C++ amd so I have a lot of doubts.
    FIRST

    using the wizzard of Qt I saw a few differnt in creating code but I did not find any explanation in Qt guide:
    If i write: Qwidget w; I obtain an Object w with all methods and Propertis and I can acces them with ( . )
    I mean w.show() same for QApplication
    but when I create for example a label, I write: QLabel Lb=new QLabel();
    Can someone explain me:
    1 - which is the right way to declare an object
    2 - what is the difference between these 2 modes
    3 - where can I read the right way in Qt guide?

    I mean ( point 3 ) when I consult the Qt guide and I check this or other classes, How cab I understand if
    I have to use this modality Class_name Object_Name;
    or

    Class_name Object_name= new Class_name();

    Please help me
    Thanks a lot

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      Read a book on C++. It will answer your question. You are asking about the concept of stack and heap based objects, so check the section on pointers. Explaining this here is going a bit far.

      Rule of thumb: Use the stack whenever possible (automatic cleanup of objects). Whenever using a QObject derived class using the stack is not possible and you need to use the heap, working with pointers.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        You're right Tobias, with some exceptions to QObject, e.g. when using QFile - which is allocated on the stack even in most of the Qt docs and examples :-)

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mkfnx
          wrote on last edited by
          #4

          You should follow the Tobias suggestion, having a solid C++ background is pretty useful when learning Qt.
          Probably you already know it but, the "Thinking in C++":http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html is a great book that you can get download for free.

          Anyway the Qt Object Model is a subject on its own, that needs its own explanation, a nice one (with pretty figures :D), is in the L2 "Presentation with notes" of the "Qt Learning material":http://qt.nokia.com/services-partners/qt-in-education/qt-in-education-course-material, altough this material is intended to be used for teaching Qt I think it's clear enough even for the beginners.

          And if you're looking for more detailed explanations check the "Qt eLearning videos":http://qt.nokia.com/developer/learning/elearning, specially the "Qt Training modules":http://qt.nokia.com/developer/learning/online/training/modules your question is answered in the "Objects int Qt" ones.

          Happy learning!

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved