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. [SOLVED]function returning QSQLQueryModel
QtWS25 Last Chance

[SOLVED]function returning QSQLQueryModel

Scheduled Pinned Locked Moved General and Desktop
qsqlquerymodelfunction
6 Posts 2 Posters 2.6k 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.
  • C Offline
    C Offline
    cpuin
    wrote on last edited by cpuin
    #1

    I want to make function returning qsqlquerymodel like this:

    QSqlQueryModel Controller::getPartners(){

    QSqlQueryModel *model = new QSqlQueryModel(this);
    model->setQuery("SELECT ID, Name, Bulstat FROM partners");
    return model;
    

    }

    i got the following error:
    no viable conversion from 'QSqlQueryModel *' to 'QSqlQueryModel' return model;

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Your function signature is wrong, getPartners returns an instance of QSqlQueryModel and the implementation returns a pointer to a QSqlQueryModel.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      C 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Your function signature is wrong, getPartners returns an instance of QSqlQueryModel and the implementation returns a pointer to a QSqlQueryModel.

        C Offline
        C Offline
        cpuin
        wrote on last edited by cpuin
        #3

        @SGaist
        Could you show how it should looks like?
        I tried also create the object in the stack, i got error too.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You got error in that case because you were returning a copy of QSqlQueryModel and you can't copy QObject derived class.

          QSqlQueryModel *Controller::getPartners() is the right signature

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          C 1 Reply Last reply
          0
          • SGaistS SGaist

            You got error in that case because you were returning a copy of QSqlQueryModel and you can't copy QObject derived class.

            QSqlQueryModel *Controller::getPartners() is the right signature

            C Offline
            C Offline
            cpuin
            wrote on last edited by
            #5

            @SGaist
            Ahhh, i see, this is something new to me!Thank you.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You have more information about why you can't copy QObject derived class here

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

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