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 764 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 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

    JonBJ 2 Replies Last reply
    0
    • Z zeroptr

      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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #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.

      Christian EhrlicherC 1 Reply Last reply
      0
      • JonBJ JonB

        @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.

        Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 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

          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

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #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.

          Christian EhrlicherC 1 Reply Last reply
          0
          • JonBJ JonB

            @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.

            Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 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

            • Login

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