Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. C++ syntax for accessing object "properties"
Forum Updated to NodeBB v4.3 + New Features

C++ syntax for accessing object "properties"

Scheduled Pinned Locked Moved Unsolved C++ Gurus
7 Posts 3 Posters 836 Views 2 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    After RTFM I am more confused then ever.
    I am assigning

    widget->setWindowTitle("Sub Window");
    

    and adding "widget" to mdiArea subwindow.
    It works fine when used directly, not via subwindow.

    In this case "window title" is identified as "properties".

    My question is - how do I access these "properties" in C++ code ?
    "getWindowTitle" does not directly exist.

    One of the suggestion is to make "properties" public.
    If so how do I do it in QWidget ?

    (It looks as one of the reasons for using MDIChild instead of bypassing it )

       QWidget *widget = new QWidget(mdiArea);
    
        // build widget in code
        QGridLayout *gridLayout = new QGridLayout(widget);
        widget->setLayout(gridLayout);
        QLabel *label = new QLabel("Hello, I am sub window!!!", widget);
        gridLayout->addWidget(label);
        // add another test  label
        QLabel *TEST_LABEL  = new QLabel("NEW TEST LABEL Hello, I am sub window!!!", widget);
        gridLayout->addWidget(TEST_LABEL);
        // need here to add to subwindow
        widget->setWindowTitle("Sub Window");
        widget->show();
        // idetify new subwindow is without  file
        // add to subwindows mdiArea
        mdiArea->addSubWindow(widget);
    

    0ed2390f-7cc5-44cb-b900-b11fc9d27d93-image.png

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      See QWidget::windowTitle property.

      Qt's style guide does not prefix the getter with get.
      Basically you setProperty and ask for property. It makes the code easier to read. In the same idea, when your property is a Boolean you will use for example setEnabled and isEnabled. Again easier to read and reason about.

      The list of properties for a class is listed at the top of the class documentation.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        Thanks , just figured it out.

        Of course being me I have to add

        makes little sense to have "set" and no "get"

        SOLVED ?

        SGaistS 1 Reply Last reply
        0
        • A Anonymous_Banned275

          Thanks , just figured it out.

          Of course being me I have to add

          makes little sense to have "set" and no "get"

          SOLVED ?

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What do you find more readable and understandable ?

          if (myObject.isEnabled()) {
              doStuff();
          }
          

          Or

          if (myObject.getEnabled()) {
              doStuff();
          }
          

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          1
          • SGaistS SGaist

            What do you find more readable and understandable ?

            if (myObject.isEnabled()) {
                doStuff();
            }
            

            Or

            if (myObject.getEnabled()) {
                doStuff();
            }
            
            A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by
            #5

            @SGaist said in C++ syntax for accessing object "properties":

            What do you find more readable and understandable ?

            if (myObject.isEnabled()) {
                doStuff();
            }
            

            Or

            if (myObject.getEnabled()) {
                doStuff();
            }
            

            OK, I'll bite.
            You probably figured out that

            1. I am not an English speaking native , hence my interpretation is often way in the left field.
            2. I wrote my first for pay program in 1973
            3. I believe in digital concept - yes / no - NOT maybe.

            "is enabled (?)" means just that - asking ( question) about the object current state. I believe most people do not make the "implied question" from the English expression.

            "GET enabled" means - irregardless of current state ( did not ask, do not care what it is ) - change it to "enabled"

            Call me pedantic , but I see the difference.
            Probably because my education and background was in hardware first. Software came later in my professional life.

            Now it is my form of self punishment... and BOTH hardware and software.

            JonBJ 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @AnneRanch said in C++ syntax for accessing object "properties":

              I am not an English speaking native , hence my interpretation is often way in the left field.

              Neither am I.

              I also have a background in hardware even if younger than you.

              That said, I did not imply that all uses of getXXX was bad. Typically "getting" a value from a hardware device falls in that case however I would use something clearer than getEnabled.

              And usually, getter related to hardware uses the return value to indicate whether the call was successful and use an output parameter to actually return the value of interest.

              While programs are not literature, making them easy to read and reason about is one big step away from maintenance hell.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • A Anonymous_Banned275

                @SGaist said in C++ syntax for accessing object "properties":

                What do you find more readable and understandable ?

                if (myObject.isEnabled()) {
                    doStuff();
                }
                

                Or

                if (myObject.getEnabled()) {
                    doStuff();
                }
                

                OK, I'll bite.
                You probably figured out that

                1. I am not an English speaking native , hence my interpretation is often way in the left field.
                2. I wrote my first for pay program in 1973
                3. I believe in digital concept - yes / no - NOT maybe.

                "is enabled (?)" means just that - asking ( question) about the object current state. I believe most people do not make the "implied question" from the English expression.

                "GET enabled" means - irregardless of current state ( did not ask, do not care what it is ) - change it to "enabled"

                Call me pedantic , but I see the difference.
                Probably because my education and background was in hardware first. Software came later in my professional life.

                Now it is my form of self punishment... and BOTH hardware and software.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @AnneRanch said in C++ syntax for accessing object "properties":

                "GET enabled" means - irregardless of current state ( did not ask, do not care what it is ) - change it to "enabled"

                That is not what the English word GET means, neither in common parlance nor in programming. What you describe is precisely what SET means, in both environments.

                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