Re: Всем привет! Помогите плз разобраться с потоками
От: sploid  
Дата: 02.08.11 13:54
Оценка:

class obj1 : public QObject
{
    Q_OBJECT
public Q_SLOTS:
    void obj_slot( )
    {
        qDebug( ) << "catch slot in th1";
    }
};

class th1 : public QThread
{
Q_SIGNALS:
    void fire_slot( );
protected:
    virtual run( )
    {
        obj1 o;
        connect( this, SIGNAL( fire_slot( ) ), &o, SLOT( obj_slot( ) ) );
        exec( );
    }
};

class th2 : public QThread
{
Q_SIGNALS:
    void fire_slot( );
protected:
    void run( )
    {
        qDebug( ) << "fire signal in th2";
        Q_EMIT fire_slot( );
    }
};

int main( int argc, char ** argv )
{
    QCoreApplication a( argc, argv );
    th1 t1;
    th2 t2;
    connect( &t2, SIGNAL( fire_slot( ) ), &t1, SIGNAL( fire_slot( ) ) );
    t1.start( );
    t2.start( );
    // тут надо подождать пока запустятся потоки
    a.exec( );
}
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.