12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #include "softnumkeyboardwidget.h"
- #include <QDesktopWidget>
- #include <QApplication>
- #include <QSharedMemory>
- int main(int argc, char *argv[])
- {
- QApplication::addLibraryPath("./plugins");
- QSharedMemory *shareMem = new QSharedMemory(QString("SingleInstanceIdentifySoftNumKeyBoard"));
- /* if the sharedmemory has not been created, it returns false, otherwise true.
- * But if the application exit unexpectedly, the sharedmemory will not detach.
- * So, we try twice.
- */
- volatile short i = 2;
- while (i--)
- {
- if (shareMem->attach(QSharedMemory::ReadOnly)) /* no need to lock, bcs it's read only */
- {
- shareMem->detach();
- }
- }
- if (shareMem->create(1))
- {
- QApplication a(argc, argv);
- QFont font = a .font();
- font.setPointSize(14);
- a.setFont(font);
- SoftNumKeyboardWidget w;
- QDesktopWidget *pDesk = QApplication::desktop();
- w.show();
- w.move((pDesk->width() - w.width()) / 2, (pDesk->height() - w.height()) / 2);// ĬÈϾÓÖÐ
- a.exec();
- if (shareMem->isAttached())
- shareMem->detach();
- delete shareMem;
- }
- return 0;
- }
|