Results 1 to 6 of 6

Thread: QThread and QSlot

  1. #1
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    3

    Default QThread and QSlot

    Hi,
    I need help because I stuck, again

    I subcass QThread:
    class Populacja : public QThread
    {//
    Q_OBJECT
    public:
    (...)
    void getWektor(){ run(); };
    signals:
    void wyslijOsobnika( QVector<Okrag> );
    protected:
    void run(){ emit wyslijOsobnika( zbiorOsobnikow[53].getGeny() ); };
    }
    Code in main class, calls after button is clicked :
    void MainWindow::slotDoTestow(){
    p = new Populacja(wektorOkragow,100,100);
    connect( p, SIGNAL( wyslijOsobnika(QVector<Okrag>) ), &obraz, SLOT( aktualizujZbiorOkregow(QVector<Okrag>) ) );
    p->start();
    };
    Slot:
    void RysujacyKolkaWidget::aktualizujZbiorOkregow( QVector<Okrag> wektorOkregow )
    {
    QMessageBox::information(this, "XXX", " Hello ");
    };
    This code doesn't work and I don't get QMessageBox
    When I change 'p->start();' to 'p->getWektor();' it works and I get QMessageBox.
    I don't know what I'm doing wrong. For me only difference between this two calls is that one is starting QThread and one isn't.

    Any clue?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QThread and QSlot

    I don't think you can use parametrized types in connect.
    Try passing only QVector, or even const QVector&.

    If you look in the debug output, you'll see some warnings from connect.

  3. #3
    Join Date
    Feb 2007
    Location
    Philadelphia, USA
    Posts
    255
    Thanks
    43
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QThread and QSlot

    I think that
    Qt Code:
    1. QVector<Okrag>
    To copy to clipboard, switch view to plain text mode 
    is probably not recognized as a data type that can be passed via signals/slots across threads. I think you need to use qRegisterMetaType.

    You need to do a typedef

    Qt Code:
    1. typedef QVector<Okrag> MyClass;
    To copy to clipboard, switch view to plain text mode 

    and then

    Qt Code:
    1. qRegisterMetaType<MyClass>("MyClass");
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    3

    Default Re: QThread and QSlot

    I wrote in file OkragVector.h:
    #ifndef OkragVector_H
    #define OkragVector_H
    #include <QMetaType>
    #include "Okrag.h"

    typedef QVector<Okrag> OkragVector;
    qRegisterMetaType<OkragVector>("OkragVector");

    #endif
    But now I got lots of errors:
    c:\qt\projekty\graphicitem\OkragVector.h(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\qt\projekty\graphicitem\OkragVector.h(8) : error C2365: 'qRegisterMetaType' : redefinition; previous definition was 'function'
    c:\qt\projekty\graphicitem\OkragVector.h(8) : error C2440: 'initializing' : cannot convert from 'const char [12]' to 'int'
    There is no context in which this conversion is possible
    When I delete QVector<Okrag> from arguments of slot/signal it's works and I get QMessageBox.

    Edit:
    Only QVector gives me:
    c:\qt\projekty\graphicitem\RysujacyKolkaWidget.h(4 0) : error C2955: 'QVector' : use of class template requires template argument list
    c:\msvc\vc\qt\include\qtcore\../../src/corelib/tools/qvector.h(96) : see declaration of 'QVector'

  5. #5
    Join Date
    Feb 2007
    Location
    Philadelphia, USA
    Posts
    255
    Thanks
    43
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QThread and QSlot

    Quote Originally Posted by Xaar View Post
    But now I got lots of errors:
    You need to put the qRegisterMetaType in a function (like main()). Just make sure you only register once.

  6. The following user says thank you to magland for this useful post:

    Xaar (6th December 2007)

  7. #6
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    3

    Default Re: QThread and QSlot

    Quote Originally Posted by magland View Post
    You need to put the qRegisterMetaType in a function (like main()). Just make sure you only register once.
    Hehe, it's works perfect.
    This is what I need.
    Thanks VERY much

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.