PDA

View Full Version : How to use the object name of push button from one class to another??



Gokulnathvc
21st March 2011, 08:08
In VC++ we may use IDOK in resource.h. which denotes the ok button. But how to use the name of the push button from one dialog to another??

Added after 1 26 minutes:

How to use the push button object name in the other dialog???

high_flyer
21st March 2011, 08:52
In VC++ we may use IDOK in resource.h.
This has nothing to do with VS (which is an IDE) but with MFC which is a GUI kit, just like Qt is.
Although it is possible to mix Qt and MFC, I don't really think this is what you are after.
Based on your question, I am not sure YOU know what you are after either.

Maybe if you explain what it is you are trying to do we can give you a shove in the right direction.

Gokulnathvc
21st March 2011, 09:33
How can i use the object name of the push button that is in a say Dialog A ... to use the push button object name of the Dialog A in Dialog B???

Octal
21st March 2011, 09:54
Maybe can you pass a const-reference to your Dialog B constructor, and then use it for your PushButton ? :



DialogB::DialogB(const QString &objectName, QWidget *parent) :
QDialog(parent)
{
/* ... Do whatever you want with objectName */
blah->setObjectName(objectName);
}

wysota
21st March 2011, 09:59
How can i use the object name of the push button that is in a say Dialog A
You can query the object name using QObject::objectName property and store it in some variable.

... to use the push button object name of the Dialog A in Dialog B???
You can use value from the variable that contains the object name stored there in the previous step.

high_flyer
21st March 2011, 10:00
How can i use the object name of the push button that is in a say Dialog A ... to use the push button object name of the Dialog A in Dialog B???
When I ask what it is you want to achieve I mean in terms of functionality, not implementation.
Your question suggests you are on a wrong way to implement something.
But what is that "something"?
If you explain what you need to have working, we might help you implement it the right way.

Gokulnathvc
21st March 2011, 10:25
No actually, Am having the push button A in Dialog A, i want to call push button A in Dialog B....

wysota
21st March 2011, 10:39
And how did you want to achieve that using object name?

Gokulnathvc
21st March 2011, 10:40
Not exactly, I need to use that push button name or object name, How to refer it??? please help me

wysota
21st March 2011, 10:47
I have no idea what you want, sorry. And trying to pull this information out of you has so far proven impossible. Maybe someone else understands what you're trying to do. Investing in a couple of proper English lessons might be a wise thing to do as you're apparently having trouble communicating.

Gokulnathvc
21st March 2011, 11:05
I want to use the name of the push button in Dialog B which push button is originally present in Dialog A.

For instance, if a function fn() is in Dialog A, if we want to use it, then we may create the object for that Dialog A class in Dialog B then, we will call. Likewise, how to call the push button from Dialog A in Dialog B.

FelixB
21st March 2011, 11:11
then you need to pass a pointer to the object, not the object name.

wysota
21st March 2011, 11:27
By the way, your "issue" is purely of C++ nature and not Qt.

Gokulnathvc
21st March 2011, 11:29
Is it possible to pass a pointer to the object in QT??

FelixB
21st March 2011, 11:32
this is c++-basic. of course is it possible!

Octal
21st March 2011, 11:33
You should maybe read a C++ book or tutorial before trying to use Qt

ChrisW67
22nd March 2011, 08:01
The "name of pushbutton" in a typical Qt dialog is a member of a private UI class instance (if Designer built it) or a private member of the dialog class itself (if you hand-coded). In either case C++ scope rules prohibit access to the push button object variable from outside the class (please notice I said accessed not called: you call methods not objects). Nothing here is Qt-specific, just standard C++.

The code that is executed when a user presses the push button is a standard C++ method, usually, but not necessarily, in the dialog class that contains the button. This code can be called from outside the class if it is declared public and not private or protected. Nothing here is Qt-specific, just standard C++.

In QDialog derived classes the accept() (roughly equivalent to pushing the OK button), reject() (roughly equivalent to pushing the Cancel button) and done() methods are all accessible from outside by default.

If you could be bothered to answer the repeated queries about what you are trying to achieve, rather than how, perhaps more specific guidance could be given.