Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. QListSpecialMethodsBase (QList and QMap) .contains results in error passing as ‘this’ argument discards qualifiers [-fpermissive]

QListSpecialMethodsBase (QList and QMap) .contains results in error passing as ‘this’ argument discards qualifiers [-fpermissive]

Scheduled Pinned Locked Moved Solved Qt 6
8 Posts 3 Posters 1.2k 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.
  • S Offline
    S Offline
    squinky86
    wrote on last edited by
    #1

    I started porting to Qt6. The issue I'm having is with every time I use the "contains()" function on a map or list. Using this line as an example, the error I get is:

    g++ -c -pipe -O2 -std=gnu++1z -Wall -Wextra -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_SQL_LIB -DQT_XML_LIB -DQT_CORE_LIB -I. -Isrc -I/opt/qt6.3-static/include -I/opt/qt6.3-static/include/QtWidgets -I/opt/qt6.3-static/include/QtGui -I/opt/qt6.3-static/include/QtNetwork -I/opt/qt6.3-static/include/QtSql -I/opt/qt6.3-static/include/QtXml -I/opt/qt6.3-static/include/QtCore -I. -I. -I/opt/qt6.3-static/mkspecs/linux-g++ -o workerassetdelete.o src/workerassetdelete.cpp
    In file included from /opt/qt6.3-static/include/QtCore/qvector.h:43,
                     from /opt/qt6.3-static/include/QtCore/QVector:1,
                     from src/dbmanager.h:25,
                     from src/workerassetdelete.cpp:20:
    /opt/qt6.3-static/include/QtCore/qlist.h: In instantiation of ‘qsizetype QtPrivate::indexOf(const QList<T>&, const U&, qsizetype) [with V = Asset; U = Asset; qsizetype = long long int]’:
    /opt/qt6.3-static/include/QtCore/qlist.h:968:30:   required from ‘qsizetype QListSpecialMethodsBase<T>::indexOf(const AT&, qsizetype) const [with AT = Asset; T = Asset; qsizetype = long long int]’
    /opt/qt6.3-static/include/QtCore/qlist.h:80:31:   required from ‘bool QListSpecialMethodsBase<T>::contains(const AT&) const [with AT = Asset; T = Asset]’
    src/workerassetdelete.cpp:86:37:   required from here
    /opt/qt6.3-static/include/QtCore/qlist.h:939:20: error: passing ‘const Asset’ as ‘this’ argument discards qualifiers [-fpermissive]
      939 |             if (*n == u)
          |                 ~~~^~~~
    In file included from src/dbmanager.h:29,
                     from src/workerassetdelete.cpp:20:
    src/asset.h:78:10: note:   in call to ‘bool Asset::operator==(const Asset&)’
       78 |     bool operator==(const Asset &right);
          |          ^~~~~~~~
    make: *** [Makefile:6555: workerassetdelete.o] Error 1
    

    In searching through these forums, I found a lot of information about serialization, but I can't find any examples of how to call contains() correctly with Qt6.
    Thanks!

    artwawA 1 Reply Last reply
    0
    • S Offline
      S Offline
      squinky86
      wrote on last edited by
      #3
      This post is deleted!
      1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        We can't really help without seeing your code which triggers this warning.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • S Offline
          S Offline
          squinky86
          wrote on last edited by
          #3
          This post is deleted!
          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            bool operator==(const Asset &right);

            this function must be const as explained here:

            /opt/qt6.3-static/include/QtCore/qlist.h:939:20: error: passing ‘const Asset’ as ‘this’ argument discards qualifiers [-fpermissive]
            939 | if (*n == u)
            | ~^~
            In file included from src/dbmanager.h:29,
            from src/workerassetdelete.cpp:20:
            src/asset.h:78:10: note: in call to ‘bool Asset::operator==(const Asset&)’
            78 | bool operator==(const Asset &right);

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            S 2 Replies Last reply
            1
            • S squinky86

              I started porting to Qt6. The issue I'm having is with every time I use the "contains()" function on a map or list. Using this line as an example, the error I get is:

              g++ -c -pipe -O2 -std=gnu++1z -Wall -Wextra -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_SQL_LIB -DQT_XML_LIB -DQT_CORE_LIB -I. -Isrc -I/opt/qt6.3-static/include -I/opt/qt6.3-static/include/QtWidgets -I/opt/qt6.3-static/include/QtGui -I/opt/qt6.3-static/include/QtNetwork -I/opt/qt6.3-static/include/QtSql -I/opt/qt6.3-static/include/QtXml -I/opt/qt6.3-static/include/QtCore -I. -I. -I/opt/qt6.3-static/mkspecs/linux-g++ -o workerassetdelete.o src/workerassetdelete.cpp
              In file included from /opt/qt6.3-static/include/QtCore/qvector.h:43,
                               from /opt/qt6.3-static/include/QtCore/QVector:1,
                               from src/dbmanager.h:25,
                               from src/workerassetdelete.cpp:20:
              /opt/qt6.3-static/include/QtCore/qlist.h: In instantiation of ‘qsizetype QtPrivate::indexOf(const QList<T>&, const U&, qsizetype) [with V = Asset; U = Asset; qsizetype = long long int]’:
              /opt/qt6.3-static/include/QtCore/qlist.h:968:30:   required from ‘qsizetype QListSpecialMethodsBase<T>::indexOf(const AT&, qsizetype) const [with AT = Asset; T = Asset; qsizetype = long long int]’
              /opt/qt6.3-static/include/QtCore/qlist.h:80:31:   required from ‘bool QListSpecialMethodsBase<T>::contains(const AT&) const [with AT = Asset; T = Asset]’
              src/workerassetdelete.cpp:86:37:   required from here
              /opt/qt6.3-static/include/QtCore/qlist.h:939:20: error: passing ‘const Asset’ as ‘this’ argument discards qualifiers [-fpermissive]
                939 |             if (*n == u)
                    |                 ~~~^~~~
              In file included from src/dbmanager.h:29,
                               from src/workerassetdelete.cpp:20:
              src/asset.h:78:10: note:   in call to ‘bool Asset::operator==(const Asset&)’
                 78 |     bool operator==(const Asset &right);
                    |          ^~~~~~~~
              make: *** [Makefile:6555: workerassetdelete.o] Error 1
              

              In searching through these forums, I found a lot of information about serialization, but I can't find any examples of how to call contains() correctly with Qt6.
              Thanks!

              artwawA Offline
              artwawA Offline
              artwaw
              wrote on last edited by
              #5

              @squinky86 said in QListSpecialMethodsBase (QList and QMap) .contains results in error passing as ‘this’ argument discards qualifiers [-fpermissive]:

              this line as an example

              you have anitpattern here

              if (toDelete.keys().contains(a))
              

              according to this https://www.kdab.com/uncovering-32-qt-best-practices-compile-time-clazy/ there should be simply

              toDelete.contains(a)
              

              Also, Q_FOREACH is rather deprecated and overall performance poor https://www.kdab.com/goodbye-q_foreach/

              I'd fix those first and then see if the error persists.

              For more information please re-read.

              Kind Regards,
              Artur

              1 Reply Last reply
              2
              • Christian EhrlicherC Christian Ehrlicher

                bool operator==(const Asset &right);

                this function must be const as explained here:

                /opt/qt6.3-static/include/QtCore/qlist.h:939:20: error: passing ‘const Asset’ as ‘this’ argument discards qualifiers [-fpermissive]
                939 | if (*n == u)
                | ~^~
                In file included from src/dbmanager.h:29,
                from src/workerassetdelete.cpp:20:
                src/asset.h:78:10: note: in call to ‘bool Asset::operator==(const Asset&)’
                78 | bool operator==(const Asset &right);

                S Offline
                S Offline
                squinky86
                wrote on last edited by squinky86
                #6

                @artwaw Thanks! You are correct - these are good code cleanups to implement.

                1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  bool operator==(const Asset &right);

                  this function must be const as explained here:

                  /opt/qt6.3-static/include/QtCore/qlist.h:939:20: error: passing ‘const Asset’ as ‘this’ argument discards qualifiers [-fpermissive]
                  939 | if (*n == u)
                  | ~^~
                  In file included from src/dbmanager.h:29,
                  from src/workerassetdelete.cpp:20:
                  src/asset.h:78:10: note: in call to ‘bool Asset::operator==(const Asset&)’
                  78 | bool operator==(const Asset &right);

                  S Offline
                  S Offline
                  squinky86
                  wrote on last edited by
                  #7

                  @Christian-Ehrlicher I'm sorry - I clicked on the wrong menu - this is the correct answer and resolved the compile issue. I can't figure out how to go back and mark this as the answer.

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    Hehe, no problem :)

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    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