Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. moving sql results using signals and slots
Forum Updated to NodeBB v4.3 + New Features

moving sql results using signals and slots

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 450 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.
  • R Offline
    R Offline
    rhx9
    wrote on 3 Oct 2021, 14:28 last edited by
    #1

    Hi,
    In my app I have a mysql class that runs in a dedicated Qthread, I want all the mysql operations to happen in this class and the results be sent through signals/slots to the main thread for displaying.
    I have a problem in sending QSqlQuery data through signals, if i do something like this in the mysql class:

    @qtc.pyqtSlot()
    def fetchAll(self):
        if(self.db.isOpen()):
            results = self.db.exec_("SELECT * FROM members")
            if not results.lastError().isValid():
                self.populate.emit(results)
    

    then on the receiving end I should define the slot like so:

    @qtc.pyqtSlot(QtSql.QSqlQuery)
    def populate(self,allMembers):
    

    to be able to iterate over the QSqlQuery and populate my widget with the data
    but this gives an error:

    QObject::connect: Cannot queue arguments of type 'QSqlQuery'
    (Make sure 'QSqlQuery' is registered using qRegisterMetaType().)
    

    I know i can convert the results to a pythonic datatype like a dict or a list in the db class which i can then send over the signal,but this will eat the memory if i have alot of rows with images or any other big data
    I'm pretty sure I'm doing this the wrong way, so what is the recommended way to move sql results using signals and slots?

    J 1 Reply Last reply 3 Oct 2021, 16:24
    0
    • R rhx9
      3 Oct 2021, 14:28

      Hi,
      In my app I have a mysql class that runs in a dedicated Qthread, I want all the mysql operations to happen in this class and the results be sent through signals/slots to the main thread for displaying.
      I have a problem in sending QSqlQuery data through signals, if i do something like this in the mysql class:

      @qtc.pyqtSlot()
      def fetchAll(self):
          if(self.db.isOpen()):
              results = self.db.exec_("SELECT * FROM members")
              if not results.lastError().isValid():
                  self.populate.emit(results)
      

      then on the receiving end I should define the slot like so:

      @qtc.pyqtSlot(QtSql.QSqlQuery)
      def populate(self,allMembers):
      

      to be able to iterate over the QSqlQuery and populate my widget with the data
      but this gives an error:

      QObject::connect: Cannot queue arguments of type 'QSqlQuery'
      (Make sure 'QSqlQuery' is registered using qRegisterMetaType().)
      

      I know i can convert the results to a pythonic datatype like a dict or a list in the db class which i can then send over the signal,but this will eat the memory if i have alot of rows with images or any other big data
      I'm pretty sure I'm doing this the wrong way, so what is the recommended way to move sql results using signals and slots?

      J Online
      J Online
      JonB
      wrote on 3 Oct 2021, 16:24 last edited by JonB 10 Mar 2021, 16:31
      #2

      @rhx9
      The answer at multithreaded QSqlQuery sums it up simply:

      QSqlQuery::prepare and QSqlQuery::bindValue methods cannot be called outside the thread created them. Hence there is no reason to pass it around in signal-slot.

      (For a big resultset, you might look at how QSqlQueryModel::fetchMore() works, but I'm not convinced that will help in your case.)

      Actually, there is a thread on this forum: QSqlQuery - execution in one thread and reading the results in another.. Also https://forum.qt.io/topic/52967/qsqlquery-exec-in-one-thread-read-result-in-another-is-it-legal

      1 Reply Last reply
      2

      1/2

      3 Oct 2021, 14:28

      • Login

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