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. passing 'const QSqlQuery' as 'this' argument discards qualifiers
Forum Updated to NodeBB v4.3 + New Features

passing 'const QSqlQuery' as 'this' argument discards qualifiers

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.0k 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.
  • Z Offline
    Z Offline
    zeroptr
    wrote on 10 Aug 2023, 08:28 last edited by
    #1

    Hi All,

    I'm trying to migrate from Qt5.6 to Qt6.5 my project is heavily SQL based...

    At my Class at header... I define a

    QSqlQueryModel *modKomponent;

    At my class constructor

    modKomponent = new QSqlQueryModel;

    on the form one of the button

    modKomponent->query().next()

    then I get error for "modKomponent->query().next()"

    passing 'const QSqlQuery' as 'this' argument discards qualifiers

    How can I solve it?

    thanks

    Linux Mint 20.04 64 Bit QT6.0.1

    J 2 Replies Last reply 10 Aug 2023, 08:41
    0
    • Z zeroptr
      10 Aug 2023, 08:28

      Hi All,

      I'm trying to migrate from Qt5.6 to Qt6.5 my project is heavily SQL based...

      At my Class at header... I define a

      QSqlQueryModel *modKomponent;

      At my class constructor

      modKomponent = new QSqlQueryModel;

      on the form one of the button

      modKomponent->query().next()

      then I get error for "modKomponent->query().next()"

      passing 'const QSqlQuery' as 'this' argument discards qualifiers

      How can I solve it?

      thanks

      J Offline
      J Offline
      JonB
      wrote on 10 Aug 2023, 08:41 last edited by JonB 8 Oct 2023, 08:42
      #2

      @zeroptr
      const QSqlQuery &QSqlQueryModel::query() const

      The const at the beginning means that the QSqlQuery it returns is const/read-only. You cannot/are not supposed to do anything to it which alters it. But QSqlQuery::next() does (or may) alter it, e.g. changing its internal state. Hence the error message.

      You are clearly not intended to do anything to modify the query returned by QSqlQueryModel::query() (I imagine it manages it all internally). I don't know why you got away with this at Qt5, whether you were never supposed to or it is an actual change in behaviour at Qt6. I guess you should review why you are trying to call next() on it when you should be letting the QSqlQueryModel handle its query without interference.

      C 1 Reply Last reply 10 Aug 2023, 09:12
      0
      • J JonB
        10 Aug 2023, 08:41

        @zeroptr
        const QSqlQuery &QSqlQueryModel::query() const

        The const at the beginning means that the QSqlQuery it returns is const/read-only. You cannot/are not supposed to do anything to it which alters it. But QSqlQuery::next() does (or may) alter it, e.g. changing its internal state. Hence the error message.

        You are clearly not intended to do anything to modify the query returned by QSqlQueryModel::query() (I imagine it manages it all internally). I don't know why you got away with this at Qt5, whether you were never supposed to or it is an actual change in behaviour at Qt6. I guess you should review why you are trying to call next() on it when you should be letting the QSqlQueryModel handle its query without interference.

        C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 10 Aug 2023, 09:12 last edited by
        #3

        @JonB with Qt5 you get the same compiler error. QSqlQuery::next() was never const.

        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
        1
        • Z zeroptr
          10 Aug 2023, 08:28

          Hi All,

          I'm trying to migrate from Qt5.6 to Qt6.5 my project is heavily SQL based...

          At my Class at header... I define a

          QSqlQueryModel *modKomponent;

          At my class constructor

          modKomponent = new QSqlQueryModel;

          on the form one of the button

          modKomponent->query().next()

          then I get error for "modKomponent->query().next()"

          passing 'const QSqlQuery' as 'this' argument discards qualifiers

          How can I solve it?

          thanks

          J Offline
          J Offline
          JonB
          wrote on 10 Aug 2023, 09:17 last edited by JonB 8 Oct 2023, 09:17
          #4

          @zeroptr
          Then per @Christian-Ehrlicher's comment it should never have worked at Qt5 either....

          The QSqlQuery assigned to a QSqlTableModel is for its use internally, to fetch all the rows from a table. You should never either need or want to call next() on it to fetch any further rows. If you want to do your own next()ing to fill a result set, for some reason, use your own QSqlQuery to do so, not one in use by a table or query model.

          C 1 Reply Last reply 10 Aug 2023, 09:43
          0
          • J JonB
            10 Aug 2023, 09:17

            @zeroptr
            Then per @Christian-Ehrlicher's comment it should never have worked at Qt5 either....

            The QSqlQuery assigned to a QSqlTableModel is for its use internally, to fetch all the rows from a table. You should never either need or want to call next() on it to fetch any further rows. If you want to do your own next()ing to fill a result set, for some reason, use your own QSqlQuery to do so, not one in use by a table or query model.

            C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 10 Aug 2023, 09:43 last edited by
            #5

            @JonB after reconsideration it might have worked when the const ref was copied to a new QSqlQuery instance
            This copy was removed in Qt6 as it's impossible to copy a query without getting strange side effects in the underlying layer.

            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
            2

            1/5

            10 Aug 2023, 08:28

            • Login

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