{
Q_OBJECT
public:
window
(QWidget *parent
= 0, Qt
::WFlags flags
= 0) : QWidget(parent, flags
) {
}
public slots:
void showMe()
{
show();
}
void hideMe()
{
hide();
}
};
class consumerThread
: public QThread{
Q_OBJECT
public:
consumerThread(fifo<int> & f):f(f)
{
start();
}
void run()
{
while(true)
{
int a;
f.pop(a);
if(a == 0)
{
emit showMe1();
emit hideMe1();
}
else
{
emit showMe2();
emit hideMe2();
}
}
}
signals:
void showMe1();
void showMe2();
void hideMe1();
void hideMe2();
private:
fifo<int> & f;
};
class producerThread
: public QThread{
public:
producerThread(fifo<int> & f):f(f)
{
start();
}
void run()
{
while(true)
{
f.push(0);
Sleep(1000);
f.push(1);
Sleep(1000);
}
}
private:
fifo<int> & f;
};
{
Q_OBJECT
public:
dispatcher()
{
consumerThread* consumer = new consumerThread(queue);
producerThread* producer = new producerThread(queue);
window1 = new window();
window2 = new window();
connect(consumer, SIGNAL(showMe1()), window1, SLOT(showMe()));
connect(consumer, SIGNAL(showMe2()), window2, SLOT(showMe()));
connect(consumer, SIGNAL(hideMe1()), window1, SLOT(hideMe()));
connect(consumer, SIGNAL(hideMe2()), window2, SLOT(hideMe()));
}
private:
fifo<int> queue;
window* window1;
window* window2;
};
class window : public QWidget
{
Q_OBJECT
public:
window(QWidget *parent = 0, Qt::WFlags flags = 0) : QWidget(parent, flags)
{
}
public slots:
void showMe()
{
show();
}
void hideMe()
{
hide();
}
};
class consumerThread : public QThread
{
Q_OBJECT
public:
consumerThread(fifo<int> & f):f(f)
{
start();
}
void run()
{
while(true)
{
int a;
f.pop(a);
if(a == 0)
{
emit showMe1();
emit hideMe1();
}
else
{
emit showMe2();
emit hideMe2();
}
}
}
signals:
void showMe1();
void showMe2();
void hideMe1();
void hideMe2();
private:
fifo<int> & f;
};
class producerThread : public QThread
{
public:
producerThread(fifo<int> & f):f(f)
{
start();
}
void run()
{
while(true)
{
f.push(0);
Sleep(1000);
f.push(1);
Sleep(1000);
}
}
private:
fifo<int> & f;
};
class dispatcher : public QObject
{
Q_OBJECT
public:
dispatcher()
{
consumerThread* consumer = new consumerThread(queue);
producerThread* producer = new producerThread(queue);
window1 = new window();
window2 = new window();
connect(consumer, SIGNAL(showMe1()), window1, SLOT(showMe()));
connect(consumer, SIGNAL(showMe2()), window2, SLOT(showMe()));
connect(consumer, SIGNAL(hideMe1()), window1, SLOT(hideMe()));
connect(consumer, SIGNAL(hideMe2()), window2, SLOT(hideMe()));
}
private:
fifo<int> queue;
window* window1;
window* window2;
};
To copy to clipboard, switch view to plain text mode
Bookmarks