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. Qt-creator's bug?

Qt-creator's bug?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 1.2k 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.
  • L Offline
    L Offline
    Limer
    wrote on 8 Dec 2018, 14:28 last edited by Limer 12 Aug 2018, 14:30
    #1

    0_1544279214045_20181208_222557.png

    The first if (curColor == Qt::white) is ok for creator, but the second failed.

    creator version is 4.8.0. (The latest qt release version).

    This is a bug ? I don't verify it at older creator version.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 8 Dec 2018, 14:34 last edited by
      #2

      hi
      Qt::darkGray is an enum / int.
      So hence the the error.

      L 2 Replies Last reply 8 Dec 2018, 14:36
      0
      • M mrjj
        8 Dec 2018, 14:34

        hi
        Qt::darkGray is an enum / int.
        So hence the the error.

        L Offline
        L Offline
        Limer
        wrote on 8 Dec 2018, 14:36 last edited by
        #3

        @mrjj But why the first if(...) is ok!!!!

        M 1 Reply Last reply 8 Dec 2018, 14:38
        0
        • L Limer
          8 Dec 2018, 14:36

          @mrjj But why the first if(...) is ok!!!!

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 8 Dec 2018, 14:38 last edited by
          #4

          @Limer
          mine does for both
          alt text

          L 1 Reply Last reply 8 Dec 2018, 14:45
          1
          • M mrjj
            8 Dec 2018, 14:34

            hi
            Qt::darkGray is an enum / int.
            So hence the the error.

            L Offline
            L Offline
            Limer
            wrote on 8 Dec 2018, 14:39 last edited by Limer 12 Aug 2018, 15:05
            #5

            @mrjj Oh!!! I get it!!! C++ follows left-to-right. QColor can't convert to int implicitly!

            ------modified -------

            QColor don't have operator int() { } conversion operator function, so the former is right, but the latter is wrong.

            1 Reply Last reply
            0
            • M mrjj
              8 Dec 2018, 14:38

              @Limer
              mine does for both
              alt text

              L Offline
              L Offline
              Limer
              wrote on 8 Dec 2018, 14:45 last edited by
              #6

              @mrjj NONONO,,,, My codes are: color == Qt::white and Qt::darkGray == color, their positions are opposite!

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 8 Dec 2018, 14:45 last edited by
                #7

                Hi
                I think what you want is
                if (col == QColor(Qt::white) )
                if (col == QColor(Qt::green) )

                that should work.

                L 1 Reply Last reply 8 Dec 2018, 14:52
                3
                • M mrjj
                  8 Dec 2018, 14:45

                  Hi
                  I think what you want is
                  if (col == QColor(Qt::white) )
                  if (col == QColor(Qt::green) )

                  that should work.

                  L Offline
                  L Offline
                  Limer
                  wrote on 8 Dec 2018, 14:52 last edited by Limer 12 Aug 2018, 15:06
                  #8

                  @mrjj QColor has the convert function http://doc.qt.io/qt-5/qcolor.html#QColor-1

                  So I can just use color == Qt::white, their data types will convert to each other implicitly.

                  But qt-creator detects color == Qt::white is right, Qt::white == color is wrong.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dheerendra
                    Qt Champions 2022
                    wrote on 8 Dec 2018, 15:08 last edited by
                    #9

                    In addition to what @mrjj is telling, there is concept called operator overloading in c++. I'm sure you aware of that. Following statement works

                    color == Qt::white
                    

                    because QColor class has '=' (operator) overloaded. Look at the following function signature.

                    QColor &
                    operator=(Qt::GlobalColor color)
                    

                    Where as there as there is no operator overaloading for (Qt::white == color )
                    Hence it does not work.

                    Dheerendra
                    @Community Service
                    Certified Qt Specialist
                    http://www.pthinks.com

                    M 1 Reply Last reply 8 Dec 2018, 15:27
                    2
                    • D dheerendra
                      8 Dec 2018, 15:08

                      In addition to what @mrjj is telling, there is concept called operator overloading in c++. I'm sure you aware of that. Following statement works

                      color == Qt::white
                      

                      because QColor class has '=' (operator) overloaded. Look at the following function signature.

                      QColor &
                      operator=(Qt::GlobalColor color)
                      

                      Where as there as there is no operator overaloading for (Qt::white == color )
                      Hence it does not work.

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 8 Dec 2018, 15:27 last edited by
                      #10

                      @dheerendra
                      Hi
                      but is that not the assignment operator it has an overload of ?
                      And not the == (compare) operator ?

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        dheerendra
                        Qt Champions 2022
                        wrote on 8 Dec 2018, 16:36 last edited by
                        #11

                        @mrjj both = and == are overloaded. In the current case it is ==.

                        Dheerendra
                        @Community Service
                        Certified Qt Specialist
                        http://www.pthinks.com

                        M 1 Reply Last reply 8 Dec 2018, 19:53
                        1
                        • D dheerendra
                          8 Dec 2018, 16:36

                          @mrjj both = and == are overloaded. In the current case it is ==.

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 8 Dec 2018, 19:53 last edited by
                          #12

                          @dheerendra
                          Ah i missed that part :)

                          1 Reply Last reply
                          0

                          3/12

                          8 Dec 2018, 14:36

                          9 unread
                          • Login

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