#ifndef MAINWINDOW_H
#define MAINWINDOW_H
 
#include <QMainWindow>
#include <QThread>
#include <QHash>
#include <QTreeWidgetItem>
 
 
 
namespace Ui {
class MainWindow;
}
 
class Vlakno : public QThread
{
Q_OBJECT
public:
    QString name;
signals:
    void send (QString s);
    void send2 (QString id, QString s);
public:
    void run ();
};
 
class MainWindow : public QMainWindow
{
    Q_OBJECT
 
private:
    QHash <QString, QTreeWidgetItem*> b;
 
private slots:
    void receive (QString s);
    void receive2 (QString id, QString s);
 
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
 
private:
    Ui::MainWindow *ui;
};
 
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
 
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
 
    for (int i = 1; i <= 1; i++)
    {
       Vlakno * v = new Vlakno;
       v->name = 'A'+i-1;
       connect ( v,    SIGNAL (send (QString)),
                 this, SLOT   (receive (QString)) );
       connect ( v,    SIGNAL (send2 (QString, QString)),
                 this, SLOT   (receive2 (QString, QString)) );
       v->start ();
    }
}
 
MainWindow::~MainWindow()
{
    delete ui;
}
 
 
void Vlakno::run()
{
    int n = 0;
    while (true)
    {
        n ++;
        emit send ("Hello " + QString::number (n) + " from " + name);
        msleep(200);
    }
}
 
void MainWindow::receive(QString s)
{
    ui->textEdit->append (s);
}
 
qtthread1.txt · Last modified: 2014/04/02 15:09 by 147.32.8.115
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki