PDA

View Full Version : instance of an application is running or not????



sinche
12th January 2006, 05:09
hi all,
The application is being developed in Linux and to explain the problem in more detail..application has 2 dialog windows(D1 & D2).Note that D2 is dynamically created based on an event taking place on D1.I come across a situation where I have to update the content displayed on D2 that is already running.I would like to know how to identify whether an instance of D2 is already runnin.The caption on each of the D2(s) that is generated are different.
Any help would be appreciated...

thanx and rgards,
sinche

sunil.thaha
12th January 2006, 05:45
You will have to maintain a pointer to the D2 and use it to update the Contents of D2



if ( ! pointerToD2 ) {
// D2 is not yet created !
// May be U can create it here
}

pointerToD2->updateTheContents( params );

sinche
12th January 2006, 06:45
ok....how to access the pointer to D2 from main.cpp.

sunil.thaha
12th January 2006, 07:53
Could u please explain what do intend to Do ?

Since accessing a pointer to a Form Created within Another is very Rare :confused:

Any way


int main() {
D1 d1;
d1.d2->updateContents()
}


Please recheck the Design before u decide to do this !!

fullmetalcoder
12th January 2006, 16:03
If you need interaction between two dialogs use the singleton pattern :

mydialog.h


#include <QtCore>
#include <QtGui>

class mydialog : public QDialog
{
Q_OBJECT

public:
static mydialog* Instance()

// your stuffs here

private:
static mydialog *inst;
}


mydialog.cpp


mydialog mydialog:: *inst = 0;

mydialog* mydialog::Instance()
{
if (inst == 0)
inst = new mydialog;
return inst;
}



constructors and destructors are declared private

sunil.thaha
16th January 2006, 05:15
Check the code
pm me if you have any doubts :)