Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. C++ % " ?
Qt 6.12 LTS is out! See what's new in the release blog

C++ % " ?

Scheduled Pinned Locked Moved Solved C++ Gurus
26 Posts 9 Posters 23.4k Views 6 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.
  • JonBJ JonB

    @koahnig ; is not an operator. I believe it is a "statement separator" (whereas Pascal had it as a "statement terminator"... or is it the other way round?).

    K Offline
    K Offline
    koahnig
    wrote on last edited by
    #14

    @JonB

    Thanks for clarification, I am so happy about that ;)

    However, with the ancient FORTRAN they discussed a COME FROM statement
    Therefore, you never know what somebody will come up with. At least FORTRAN did not require a "statement separator" nor a "statement terminator". The logical end of aline was the end of the punching card after 80 chars respectively you had to subtract 8 digits for the line number.

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    1
    • JonBJ JonB

      @J.Hilk
      LOL, I don't know about Boost. But how's about the subject of this post: how is this QString % operator related to original modulus?

      K Offline
      K Offline
      Konstantin Tokarev
      wrote on last edited by
      #15

      @JonB said in C++ % " ?:

      @J.Hilk
      LOL, I don't know about Boost. But how's about the subject of this post: how is this QString % operator related to original modulus?

      modulus has no established meaning for strings, and % looks somewhat similar to + :)

      1 Reply Last reply
      3
      • K Offline
        K Offline
        Konstantin Tokarev
        wrote on last edited by
        #16

        Though you should better define QT_USE_QSTRINGBUILDER and simply use + everywhere instead of %

        JonBJ 1 Reply Last reply
        4
        • K Konstantin Tokarev

          Though you should better define QT_USE_QSTRINGBUILDER and simply use + everywhere instead of %

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

          @Konstantin-Tokarev said in C++ % " ?:

          Though you should better define QT_USE_QSTRINGBUILDER and simply use + everywhere instead of %

          Ooohhh, the plot thickens...!

          1 Reply Last reply
          0
          • JonBJ JonB

            @J.Hilk
            LOL, I don't know about Boost. But how's about the subject of this post: how is this QString % operator related to original modulus?

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

            @JonB Qt has ome confusing operaters as well.

            for example take QVectors +=

            QVector<T> QVector::operator+(const QVector<T> &other) const
            

            I would asume this to be Vector addtion

            QVector v1{a,b,c};
            QVector v2{d,e,f};
            
            //What one would expect
            v1 += v2; -> {a+d, b+e, c+f}
            
            //what one gets
            v1 +=v2; _> {a,b,c,d,e,f}
            

            I mean, this technically makes sense. QVector is to generic to have this operation, thats why there is QVector2D, 3D, 4D etc

            It still confused me the first time I used it. I did not expect += to be equal to .append() or <<;

            In this paticular example I have would prefere a missing += operator :-).


            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.

            jsulmJ JKSHJ 2 Replies Last reply
            0
            • J.HilkJ J.Hilk

              @JonB Qt has ome confusing operaters as well.

              for example take QVectors +=

              QVector<T> QVector::operator+(const QVector<T> &other) const
              

              I would asume this to be Vector addtion

              QVector v1{a,b,c};
              QVector v2{d,e,f};
              
              //What one would expect
              v1 += v2; -> {a+d, b+e, c+f}
              
              //what one gets
              v1 +=v2; _> {a,b,c,d,e,f}
              

              I mean, this technically makes sense. QVector is to generic to have this operation, thats why there is QVector2D, 3D, 4D etc

              It still confused me the first time I used it. I did not expect += to be equal to .append() or <<;

              In this paticular example I have would prefere a missing += operator :-).

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #19

              @J.Hilk To be honest I would be rather confused if it would do

              v1 += v2; -> {a+d, b+e, c+f}
              

              A vector is not a number or something, it is a container. Or is it because it is called "vector" and you expect it to behave like a vector in math? :-)

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              K J.HilkJ 2 Replies Last reply
              0
              • jsulmJ jsulm

                @J.Hilk To be honest I would be rather confused if it would do

                v1 += v2; -> {a+d, b+e, c+f}
                

                A vector is not a number or something, it is a container. Or is it because it is called "vector" and you expect it to behave like a vector in math? :-)

                K Offline
                K Offline
                koahnig
                wrote on last edited by
                #20

                @jsulm said in C++ % " ?:

                @J.Hilk To be honest I would be rather confused if it would do

                v1 += v2; -> {a+d, b+e, c+f}
                

                A vector is not a number or something, it is a container. Or is it because it is called "vector" and you expect it to behave like a vector in math? :-)

                That is debatable and apparently dependent on your background. The foprm you find confusing would be the most logical version for me.

                Vote the answer(s) that helped you to solve your issue(s)

                jsulmJ 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @J.Hilk To be honest I would be rather confused if it would do

                  v1 += v2; -> {a+d, b+e, c+f}
                  

                  A vector is not a number or something, it is a container. Or is it because it is called "vector" and you expect it to behave like a vector in math? :-)

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

                  @jsulm I used to use only QList as a container, and one day I needed to do Vector operations. In my youthfull naiveté I assumed QVector = linear algebra vector.
                  I learned quickly thats not the case 🤷

                  Ever since, I prefere using QVector over QList.😉


                  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
                  • K koahnig

                    @jsulm said in C++ % " ?:

                    @J.Hilk To be honest I would be rather confused if it would do

                    v1 += v2; -> {a+d, b+e, c+f}
                    

                    A vector is not a number or something, it is a container. Or is it because it is called "vector" and you expect it to behave like a vector in math? :-)

                    That is debatable and apparently dependent on your background. The foprm you find confusing would be the most logical version for me.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #22

                    @koahnig Yes, that's true.
                    @J-Hilk I'm actually wondering why it is called vector? Something like "QDynamicArray" would be less confusing.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    K kshegunovK 2 Replies Last reply
                    0
                    • jsulmJ jsulm

                      @koahnig Yes, that's true.
                      @J-Hilk I'm actually wondering why it is called vector? Something like "QDynamicArray" would be less confusing.

                      K Offline
                      K Offline
                      koahnig
                      wrote on last edited by
                      #23

                      @jsulm

                      In the mathematical sense it is alwways a vector, but in spaces with different dimensions. All operators are bascially identical, therefore "real" engineers can accept this. Personally I doubt that the definition of basically changing the space dimension during an addition is conform with pure mathematics. On the other hand you never know what they think/thoght in those areas ;)

                      Vote the answer(s) that helped you to solve your issue(s)

                      1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @koahnig Yes, that's true.
                        @J-Hilk I'm actually wondering why it is called vector? Something like "QDynamicArray" would be less confusing.

                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on last edited by kshegunov
                        #24

                        @jsulm said in C++ % " ?:

                        I'm actually wondering why it is called vector?

                        In linear (and higher) algebra, a vector is an ordered set, or more precisely (and formally speaking) - it is the element of the linear space defined over a field; usually the field of real or complex numbers. Very similar to what you call a vector in programming.

                        It's just convenience that in Qt you have the + defined to mean merging of two arrays, and not the mathematical operation, as you don't regularly require the mathematical properties of a vector; it's just not so useful in everyday life.

                        Read and abide by the Qt Code of Conduct

                        1 Reply Last reply
                        0
                        • J.HilkJ J.Hilk

                          @JonB Qt has ome confusing operaters as well.

                          for example take QVectors +=

                          QVector<T> QVector::operator+(const QVector<T> &other) const
                          

                          I would asume this to be Vector addtion

                          QVector v1{a,b,c};
                          QVector v2{d,e,f};
                          
                          //What one would expect
                          v1 += v2; -> {a+d, b+e, c+f}
                          
                          //what one gets
                          v1 +=v2; _> {a,b,c,d,e,f}
                          

                          I mean, this technically makes sense. QVector is to generic to have this operation, thats why there is QVector2D, 3D, 4D etc

                          It still confused me the first time I used it. I did not expect += to be equal to .append() or <<;

                          In this paticular example I have would prefere a missing += operator :-).

                          JKSHJ Offline
                          JKSHJ Offline
                          JKSH
                          Moderators
                          wrote on last edited by JKSH
                          #25

                          @J.Hilk said in C++ % " ?:

                          @JonB Qt has ome confusing operaters as well.

                          for example take QVectors +=

                          QVector<T> QVector::operator+(const QVector<T> &other) const
                          

                          I would asume this to be Vector addtion

                          QVector v1{a,b,c};
                          QVector v2{d,e,f};
                          
                          //What one would expect
                          v1 += v2; -> {a+d, b+e, c+f}
                          
                          //what one gets
                          v1 +=v2; _> {a,b,c,d,e,f}
                          

                          I mean, this technically makes sense. QVector is to generic to have this operation, thats why there is QVector2D, 3D, 4D etc

                          It still confused me the first time I used it. I did not expect += to be equal to .append() or <<;

                          In this paticular example I have would prefere a missing += operator :-).

                          Wait till you try + or += on QJsonArray ;)

                          QJsonArray a1{1, 2, 3};
                          QJsonArray a2{4, 5, 6};
                          
                          a1 += a2;
                          // a1 now has 4 elements: 3 numbers and 1 array
                          

                          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                          J.HilkJ 1 Reply Last reply
                          3
                          • JKSHJ JKSH

                            @J.Hilk said in C++ % " ?:

                            @JonB Qt has ome confusing operaters as well.

                            for example take QVectors +=

                            QVector<T> QVector::operator+(const QVector<T> &other) const
                            

                            I would asume this to be Vector addtion

                            QVector v1{a,b,c};
                            QVector v2{d,e,f};
                            
                            //What one would expect
                            v1 += v2; -> {a+d, b+e, c+f}
                            
                            //what one gets
                            v1 +=v2; _> {a,b,c,d,e,f}
                            

                            I mean, this technically makes sense. QVector is to generic to have this operation, thats why there is QVector2D, 3D, 4D etc

                            It still confused me the first time I used it. I did not expect += to be equal to .append() or <<;

                            In this paticular example I have would prefere a missing += operator :-).

                            Wait till you try + or += on QJsonArray ;)

                            QJsonArray a1{1, 2, 3};
                            QJsonArray a2{4, 5, 6};
                            
                            a1 += a2;
                            // a1 now has 4 elements: 3 numbers and 1 array
                            
                            J.HilkJ Offline
                            J.HilkJ Offline
                            J.Hilk
                            Moderators
                            wrote on last edited by
                            #26

                            @JKSH said in C++ % " ?:

                            Wait till you try + or += on QJsonArray ;)

                            QJsonArray a1{1, 2, 3};
                            QJsonArray a2{4, 5, 6};
                            
                            a1 += a2;
                            // a1 now has 4 elements: 3 numbers and 1 array
                            

                            😑😔
                            of course it does.

                            Not a fan!


                            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
                            1

                            • Login

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