Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Pretty C++ general question (using Qt)
QtWS25 Last Chance

Pretty C++ general question (using Qt)

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 548 Views
  • 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.
  • U Offline
    U Offline
    U7Development
    wrote on last edited by U7Development
    #1

    Hi mates.. first of all, my apologies if this does not belong to Qt Development itself, i guess is somehow related...

    I have many QLabels on my form, i decided to use a standard vector to contain them, so i can iterate the vector to configure my QLabels shortly. For ranged detects the QLabel function members, but standard iterator does not, why?

    for (std::vector<QLabel*>::iterator ite = vQLabels.begin(); ite != vQLabels.end(); ++ite) { 
            *ite = new QLabel;       // <--- this is OK
            *ite->setStyleSheet(C_STYLESHEET_FIELD);     // <---- Error no member named setStyleSheet in __gnu_cxx
    }
    

    it is supposed that ite is the iterator pointing to QLabel object isn't ?

    But this works....

    for (auto& v : vQLabels){
          v->setStyleSheet(C_STYLESHEET_FIELD);     // <----- correct
    }
    

    Any ideas?.
    Thanks so much.

    JonBJ 1 Reply Last reply
    0
    • U U7Development

      Hi mates.. first of all, my apologies if this does not belong to Qt Development itself, i guess is somehow related...

      I have many QLabels on my form, i decided to use a standard vector to contain them, so i can iterate the vector to configure my QLabels shortly. For ranged detects the QLabel function members, but standard iterator does not, why?

      for (std::vector<QLabel*>::iterator ite = vQLabels.begin(); ite != vQLabels.end(); ++ite) { 
              *ite = new QLabel;       // <--- this is OK
              *ite->setStyleSheet(C_STYLESHEET_FIELD);     // <---- Error no member named setStyleSheet in __gnu_cxx
      }
      

      it is supposed that ite is the iterator pointing to QLabel object isn't ?

      But this works....

      for (auto& v : vQLabels){
            v->setStyleSheet(C_STYLESHEET_FIELD);     // <----- correct
      }
      

      Any ideas?.
      Thanks so much.

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

      @U7Development said in Pretty C++ general question (using Qt):

      *it->setStyleSheet(C_STYLESHEET_FIELD); // <---- Error no member named setStyleSheet in __gnu_cxx

      Guess (I like making these ;) ): what's the precedence of that leading *, compared to ->? Isn't it supposed to be:

      (*it)->setStyleSheet(C_STYLESHEET_FIELD);
      
      1 Reply Last reply
      5
      • U Offline
        U Offline
        U7Development
        wrote on last edited by U7Development
        #3

        ohh you are right that works.. thanks.

        what i did not get is ite is supposed to be a pointer poiting to the QLabel pointer itself .. so theoretically if I use -> I could access to member functions too... seems weird isn't ?.

        for (std::vector<QLabel*>::iterator ite = vQLabels.begin(); ite != vQLabels.end(); ++ite) { 
                *ite = new QLabel;     
                QLabel*& lab = *ite;
                lab->setStyleSheet(C_STYLESHEET_FIELD);     // <--- this is OK
        }
        

        Is the (*) a conventional prefix to use while containing pointers only ?
        Thanks again..

        J.HilkJ 1 Reply Last reply
        0
        • U U7Development

          ohh you are right that works.. thanks.

          what i did not get is ite is supposed to be a pointer poiting to the QLabel pointer itself .. so theoretically if I use -> I could access to member functions too... seems weird isn't ?.

          for (std::vector<QLabel*>::iterator ite = vQLabels.begin(); ite != vQLabels.end(); ++ite) { 
                  *ite = new QLabel;     
                  QLabel*& lab = *ite;
                  lab->setStyleSheet(C_STYLESHEET_FIELD);     // <--- this is OK
          }
          

          Is the (*) a conventional prefix to use while containing pointers only ?
          Thanks again..

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by J.Hilk
          #4

          @U7Development said in Pretty C++ general question (using Qt):

          Is the (*) a conventional prefix to use while containing pointers only ?
          Thanks again..

          the * has generally speaking 2 roles:

          • When used in a declaration (e.g. QLabel *label), it "creates" a pointer variable
          • When not used in a declaration, it is a dereference operator

          You can read it as "the value pointed to by"
          see here for more information


          edit:

          just as an FYI you could also write
          (*(*it)).setStyleSheet(C_STYLESHEET_FIELD);
          See here for more information


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          JonBJ 1 Reply Last reply
          4
          • J.HilkJ J.Hilk

            @U7Development said in Pretty C++ general question (using Qt):

            Is the (*) a conventional prefix to use while containing pointers only ?
            Thanks again..

            the * has generally speaking 2 roles:

            • When used in a declaration (e.g. QLabel *label), it "creates" a pointer variable
            • When not used in a declaration, it is a dereference operator

            You can read it as "the value pointed to by"
            see here for more information


            edit:

            just as an FYI you could also write
            (*(*it)).setStyleSheet(C_STYLESHEET_FIELD);
            See here for more information

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

            @J-Hilk said in Pretty C++ general question (using Qt):

            the * has generally speaking 2 roles:

            So not multiplication then? ;-)

            Pl45m4P J.HilkJ 2 Replies Last reply
            2
            • JonBJ JonB

              @J-Hilk said in Pretty C++ general question (using Qt):

              the * has generally speaking 2 roles:

              So not multiplication then? ;-)

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by Pl45m4
              #6

              @JonB

              Multiplication?!
              I thought asterisk is a wildcard character in C++? :o

              QString a = "DoNotBelieve";
              QString b = "WhatImWritingHere";
              
              QString aa = "Seriously.Just.Dont";
              QString bb = "Seriously.Just.Dont";
              
              if ( *a == *b)
              {
                    qDebug() << "true, because aa = bb";
              }
              
              

              EDIT:

              It hurts even MY eyes :D


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              0
              • JonBJ JonB

                @J-Hilk said in Pretty C++ general question (using Qt):

                the * has generally speaking 2 roles:

                So not multiplication then? ;-)

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @JonB what is multiplication, but a chain of addition? 😎

                @Pl45m4
                does this compile for you? What compiler?


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                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