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?
Forum Updated to NodeBB v4.3 + New Features

Qt-creator's bug?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 1.3k 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.
  • mrjjM mrjj

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

    LimerL Offline
    LimerL Offline
    Limer
    wrote on last edited by
    #3

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

    mrjjM 1 Reply Last reply
    0
    • LimerL Limer

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

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @Limer
      mine does for both
      alt text

      LimerL 1 Reply Last reply
      1
      • mrjjM mrjj

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

        LimerL Offline
        LimerL Offline
        Limer
        wrote on last edited by Limer
        #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
        • mrjjM mrjj

          @Limer
          mine does for both
          alt text

          LimerL Offline
          LimerL Offline
          Limer
          wrote on 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
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #7

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

            that should work.

            LimerL 1 Reply Last reply
            3
            • mrjjM mrjj

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

              that should work.

              LimerL Offline
              LimerL Offline
              Limer
              wrote on last edited by Limer
              #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
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Qt Champions 2022
                wrote on 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

                mrjjM 1 Reply Last reply
                2
                • dheerendraD dheerendra

                  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.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 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
                  • dheerendraD Offline
                    dheerendraD Offline
                    dheerendra
                    Qt Champions 2022
                    wrote on 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

                    mrjjM 1 Reply Last reply
                    1
                    • dheerendraD dheerendra

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

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @dheerendra
                      Ah i missed that part :)

                      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