PDA

View Full Version : object handling issue



prolink007
12th April 2010, 00:16
Hello,

I was wondering if you guys could help me out. Here is what i am trying to do...

I am needing to create an instance of an object. And i need all my other objects to have access to this object. I need to create the instance of the object in my "mainwindow".

So basically, "mainwindow" is going to have a button. The user clicks the button and a dialog pops up. They put in some input and then the dialog needs to use the object that was created in "mainwindow" to apply some changes. I figured i could just pass the object to the dialog box class... but i dont know how to do that in qt. I am using the gui to create my dialogs and mainwindow. If i need to clarify this, let me know. I would prefer not to post any code, since this is a very general question... should be easy to just answer with some code examples or something.

Thanks in advance.

faldzip
12th April 2010, 07:42
If you have your own dialog class, then just add some method like void setMyObject(MyObject &obj) and call it before dialog.exec();
But if you want to access this object in many different places and there would be only one instance of it in whole application, then I suggest using Singleton pattern.