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. QSqlQuery does not return a record set?
Forum Updated to NodeBB v4.3 + New Features

QSqlQuery does not return a record set?

Scheduled Pinned Locked Moved Solved General and Desktop
qsqlqueryresults
7 Posts 2 Posters 525 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.
  • J Offline
    J Offline
    jdent
    wrote on 31 Mar 2024, 16:58 last edited by
    #1

    Currently I process a QSqlQuery query row by row in a while(q.next()) loop. Is there no way of capturing the result of a query into a container, a result set...

    C 1 Reply Last reply 31 Mar 2024, 17:27
    0
    • J jdent
      31 Mar 2024, 19:59

      @Christian-Ehrlicher How do I pass all records into a vector??

      I want to do this:

      		std::vector<PasswordRecord> vec;
      		QSqlQuery q;
      		if(! q.exec(SQL::FindAllPassword))
      		{
      			showError(q.lastError());
      			return vec;
      		}
      		while(q.next())
      		{
      			PasswordRecord rec(q);
      			vec.push_back(rec);
      		}
      		return vec;
      

      How do i program PasswordRecord ?? There should be a way to get the result set of the QSqlQuery!! As in .NET!!

      C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 31 Mar 2024, 20:04 last edited by
      #6

      You get the sql record out of a query with... QSqlQuery::record(). If you want to store it into your own structure then you have to convert it by yourself.

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

      J 1 Reply Last reply 31 Mar 2024, 20:43
      1
      • J jdent
        31 Mar 2024, 16:58

        Currently I process a QSqlQuery query row by row in a while(q.next()) loop. Is there no way of capturing the result of a query into a container, a result set...

        C Online
        C Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 31 Mar 2024, 17:27 last edited by
        #2

        @jdent what did you try and what do you want to do?

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

        J 1 Reply Last reply 31 Mar 2024, 19:33
        0
        • C Christian Ehrlicher
          31 Mar 2024, 17:27

          @jdent what did you try and what do you want to do?

          J Offline
          J Offline
          jdent
          wrote on 31 Mar 2024, 19:33 last edited by
          #3

          @Christian-Ehrlicher I want to do a FindAll() method that returns all rows of a table in a std::vector -- such a simple thing seems impossible in Qt...

          C 1 Reply Last reply 31 Mar 2024, 19:36
          0
          • J jdent
            31 Mar 2024, 19:33

            @Christian-Ehrlicher I want to do a FindAll() method that returns all rows of a table in a std::vector -- such a simple thing seems impossible in Qt...

            C Online
            C Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 31 Mar 2024, 19:36 last edited by
            #4

            @jdent Then pass all records into a vector and search in them - what's the problem?

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

            J 1 Reply Last reply 31 Mar 2024, 19:59
            1
            • C Christian Ehrlicher
              31 Mar 2024, 19:36

              @jdent Then pass all records into a vector and search in them - what's the problem?

              J Offline
              J Offline
              jdent
              wrote on 31 Mar 2024, 19:59 last edited by jdent
              #5

              @Christian-Ehrlicher How do I pass all records into a vector??

              I want to do this:

              		std::vector<PasswordRecord> vec;
              		QSqlQuery q;
              		if(! q.exec(SQL::FindAllPassword))
              		{
              			showError(q.lastError());
              			return vec;
              		}
              		while(q.next())
              		{
              			PasswordRecord rec(q);
              			vec.push_back(rec);
              		}
              		return vec;
              

              How do i program PasswordRecord ?? There should be a way to get the result set of the QSqlQuery!! As in .NET!!

              C 1 Reply Last reply 31 Mar 2024, 20:04
              0
              • J jdent
                31 Mar 2024, 19:59

                @Christian-Ehrlicher How do I pass all records into a vector??

                I want to do this:

                		std::vector<PasswordRecord> vec;
                		QSqlQuery q;
                		if(! q.exec(SQL::FindAllPassword))
                		{
                			showError(q.lastError());
                			return vec;
                		}
                		while(q.next())
                		{
                			PasswordRecord rec(q);
                			vec.push_back(rec);
                		}
                		return vec;
                

                How do i program PasswordRecord ?? There should be a way to get the result set of the QSqlQuery!! As in .NET!!

                C Online
                C Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 31 Mar 2024, 20:04 last edited by
                #6

                You get the sql record out of a query with... QSqlQuery::record(). If you want to store it into your own structure then you have to convert it by yourself.

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

                J 1 Reply Last reply 31 Mar 2024, 20:43
                1
                • C Christian Ehrlicher
                  31 Mar 2024, 20:04

                  You get the sql record out of a query with... QSqlQuery::record(). If you want to store it into your own structure then you have to convert it by yourself.

                  J Offline
                  J Offline
                  jdent
                  wrote on 31 Mar 2024, 20:43 last edited by
                  #7

                  @Christian-Ehrlicher Thanks!!

                  1 Reply Last reply
                  0
                  • J jdent has marked this topic as solved on 31 Mar 2024, 20:43

                  1/7

                  31 Mar 2024, 16:58

                  • Login

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