السلام عليكم و رحمة الله تعالى و بركاته،
شكرا على هذا البرنامج فنحن ننتظر النسخة النعائية بفارغ الصبر
اطلعت هلى الكود و قمت بتجريبه و لكن ليس لهذه النسخة بل النسخة الموجودة في قسم المشاريع البرمجية لانها تعتمد على QSound فقط (ليس لدي وقت لاجربها مع الـ phonon و لكن سأجربه قريبا ان شاء الله)، فقط احدثت بعض التغييرات بالنسة للملف الذي لا يسمح بالعمل لأكثر من نسخة واحدة، فما رأيك بستعمال الصف QSharedMemory :
بالنسبة للـ main:
CODE:
#include <QApplication>
#include <QtSql>
#include <QMessageBox>
#include <QTextStream>
#include <QFile>
#include <QFont>
#include <QSharedMemory>
#include "window.h"
#include "services.h"
#include "database.h"
int main(int argc,char* argv[])
{
Q_INIT_RESOURCE(gui);
QApplication app(argc,argv);
//QApplication::setFont(QFont("Tahoma"));
qint64 processId = app.applicationPid();
QSharedMemory sharedMemory;
Services services;
sharedMemory.setKey("pid");
// trying to create a shared memory segment
if(!sharedMemory.create(sizeof(processId)))
{
// if the segment already exists (an instance of the application is already running)
if(sharedMemory.error() == QSharedMemory::AlreadyExists)
{
if(sharedMemory.attach(QSharedMemory::ReadOnly))
{
// we save data of the first instance
sharedMemory.lock();
qint64 p = *(qint64 *)sharedMemory.constData();
sharedMemory.unlock();
// calling QMessageBox::critical, we can't calling it in main (main dosn't support UTF-8)
services.notSingle();
return 1;
}
}
else
{
// error ...
qDebug() << sharedMemory.errorString();
}
}
else
{
// first run of application, we save the ID
sharedMemory.lock();
memcpy(sharedMemory.data(), &processId, sharedMemory.size());
sharedMemory.unlock();
}
Database db;
// check if another instance of program run in memory.
/*if( !services.isSignle() )
return false;*/
// load style sheet
services.loadStyleSheet("style");
// check availability of place_settings file.
if( !services.createPlaceSettingsFile() )
return false;
// check availability of program_settings file.
if( !services.createProgramSettingsFile() )
return false;
// check availability of Database file.
if( !db.checkDatabase() )
return false;
// connect to SQLite database.
if( !db.makeConnection() )
return false;
// Create Almoathen Object and pass to it the initial(Previous) configuration.
Window Almoathen(services.readPlaceSettingsFile());
Almoathen.show();
Almoathen.setFixedSize(QSize(320,366));
return app.exec();
}
استعملت Services::notSingle() من نوع void في مكان isSignle() الشرح في التعليقات، و بهذا تتخلص من الملف و سلبياته
بالنسبة للـ services.h
CODE:
void Services::notSingle()
{
QMessageBox::critical(0,QObject::trUtf8("خطأ في التشغيل"),QObject::trUtf8("يوجد نسخة من البرنامج تعمل حاليا ، لا تستطيع تشغيل اكثر من نسخة واحدة"),QMessageBox::Close);
}
مع حذف جميع التعيمات الخاصة بالملف Lock من constructer و غيرها....
سأقوم ببناء البرناج على منصة الماك عندما اجد وقت فراغ ان شاء الله، و الرجاء الاكثار من التعليقات لكل دالة و كل متغير حتى نفهم الكود بسرعة، و سأحاول تحويل الكود الى لغة objectif-c ليستطيع البرنامج العمل على اجهزة الـ iphone ان شاء الله...
و السلام عليكم و رحمة الله تعالى و بركاته
