http://qt.nokia.com/products/appdev/add-on-products/catalog/4
在single application中, main函数里很奇怪, 要有一个能产生moc的类才行, 继承一个QTextEdit, 然后使用Q_OBJECT, 生成main.moc, 在#include "main.moc", 就可以了.
#include <qtsingleapplication.h>
#include <QtGui/QTextEdit>
class TextEdit : public QTextEdit
{
Q_OBJECT
public:
TextEdit(QWidget *parent = 0)
: QTextEdit(parent)
{}
public slots:
void append(const QString &str)
{
QTextEdit::append(str);
}
};
#include "main.moc"
int main(int argc, char **argv)
{
QtSingleApplication instance(argc, argv);
if (instance.sendMessage("Wake up!"))
return 0;
TextEdit logview;
logview.setReadOnly(true);
logview.show();
instance.setActivationWindow(&logview);
QObject::connect(&instance, SIGNAL(messageReceived(const QString&)),
&logview, SLOT(append(const QString&)));
return instance.exec();
}