1

Im trying to send parameter to a Qthread that is not the main thread. i have this object in my main thread and i want to send it to another thread:

q = Queue()

I want so send q to this thread:

class Sender(QtCore.QThread):
def __init__(self,q):
    super(Sender,self).__init__()
    self.q=q
def run(self):

    while True:

        try: line = q.get_nowait()
         # or q.get(timeout=.1)
        except Empty: 
            pass
        else: 
           self.emit(QtCore.SIGNAL('tri()')) 

Im trying this:

class Sender(QtCore.QThread):
    def __init__(self,q):
        super(Sender,self).__init__()
        self.q=q
self.sender= Sender(q)

But im getting this error:

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

How can i do this? Please help!

karensantana
  • 1,599
  • 4
  • 21
  • 34
  • Which line is raising that error? Your `QThread` subclass looks correct (aside from not passing the `parent`. It must be another line. – jdi Dec 03 '12 at 00:33
  • Possibly related: http://stackoverflow.com/questions/2104779/qobject-qplaintextedit-multithreading-issues – unutbu Dec 03 '12 at 00:33
  • @jdi the compiler doesn't show the specific line! – karensantana Dec 03 '12 at 00:36
  • @jdi i added thread's code! Please check it! – karensantana Dec 03 '12 at 00:54
  • class Sender. It is all that i do in the thread. – karensantana Dec 03 '12 at 01:22
  • Whatever is connected to your `tri()` slot is doing something bad apparently. Why do you need a thread do this work? It just spins waiting for queue items. You might as well just emit a signal in the main thread with these objects. – jdi Dec 03 '12 at 01:29
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/20494/discussion-between-karensantana-and-jdi) – karensantana Dec 03 '12 at 01:30
  • possible duplicate of [Qt: Not registered qRegisterMetaType()](http://stackoverflow.com/questions/13638993/qt-not-registered-qregistermetatype) – Kamil Klimek Dec 03 '12 at 09:04
  • STOP! Stop asking same question so many times. Just STOP! Instead think how could you get answer in existing question. – Kamil Klimek Dec 03 '12 at 09:04

1 Answers1

3

There is no problem with your QThread subclass, and how you are setting it up to pass a Queue object. Though I do also recommend passing and setting an optional parent as the second parameter.

What you are mostly likely running into is you are passing objects that perform QtGui operations (drawing related) into your thread. If that is the case, you cannot call any QtGui drawing related methods. They all must be performed in the main thread. Do any data processing in other threads and then emit signals for the main thread to do widget updates.

Look for what you are sending into the queue, and specifically what you are doing with it inside of your thread, as a cue to the source of the error. Somewhere, you are doing something with a QTextCursor, which is trying to trigger and queue up a paint event.

jdi
  • 90,542
  • 19
  • 167
  • 203