[Qt-interest] same code but different results on Windows and Mac
Yifei Li
yifli at mtu.edu
Sun Oct 17 01:08:12 CEST 2010
Hi all,
In the following minimal example, I want to show two messages one after another with some delay in between.
Running this code on Windows 7 gives expected results, however, Mac OS (snow leopard) will show two messages together.
Can someone explain why there's such a difference? Thanks
Yifei
#include <QtGui/QApplication>
#include <QWidget>
#include <QThread>
#include <QVBoxLayout>
#include <QTextEdit>
class Plugin : public QObject {
Q_OBJECT
public:
void exec();
signals:
void displayMessage(const QString&);
void pause();
};
class Worker : public QThread {
Q_OBJECT
public:
Worker(Plugin* p) : m_plugin(p) {}
protected:
void run() {m_plugin->exec();}
private slots:
void pause() { sleep(1); }
private:
Plugin* m_plugin;
};
#include "main.moc"
void Plugin::exec()
{
emit displayMessage("hello1");
emit pause();
emit displayMessage("hello2");
emit pause();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget* mainWidget = new QWidget;
QVBoxLayout *layout = new QVBoxLayout;
QTextEdit* view = new QTextEdit;
layout->addWidget(view);
mainWidget->setLayout(layout);
mainWidget->show();
Plugin* p = new Plugin;
Worker* w = new Worker(p);
QObject::connect(p, SIGNAL(pause()), w, SLOT(pause()));
QObject::connect(p, SIGNAL(displayMessage(const QString&)), view, SLOT(append(const QString&)));
w->start();
return a.exec();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101016/a03ba438/attachment.html
More information about the Qt-interest-old
mailing list