Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED]function returning QSQLQueryModel

    General and Desktop
    qsqlquerymodel function
    2
    6
    2226
    Loading More Posts
    • 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
      cpuin last edited by cpuin

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • C
          cpuin @SGaist last edited by cpuin

          @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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • C
              cpuin @SGaist last edited by

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

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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 Reply Quote 1
                • First post
                  Last post