For those new to message boards please try to follow a few simple rules when posting your question.
Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
Keep the subject line brief, but descriptive. eg "File Serialization problem"
Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
No advertising or soliciting.
We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
I have limited access to the object , but I can retrieve data of interest - in this case dimensions of one of the GUI objects.
Form_Widget *FW = new Form_Widget(); // object
QRect dimensions = FW->geometry(); // returns dimensions of specific part of the object
int start_X = dimensions.x2; //can't do, QRect / dimensions are private
I think I need to read-up on "friend" - that semms to be the real OOP ticket
On the contrary: that might take you into a non-OOP design.
The idea of using public member functions is to make your code independent of internal implementation details of other classes. In your case, a class representing a rectangle might keep a corner of the rectangle and its dimensions. Another one might keep two opposite corners or some other combination. If you try to access private members of the class your code will need to change when or if the implementation of the rectangle changes. If you stick to using only public interface, the internal details of the rectangle class may change but your code will remain the same.
You cannot "buy" your way inside a class using a friend declaration. Just like in real life, the friendship is not a symmetrical relation. If you put a friend QRect declaration inside your class that doesn't give you any special access rights. It gives access rights to QRect to your class but obviously QRect is not going to use those rights. You would need to modify the QRect header file to insert a friend declaration mentioning your class. This is very intrusive and basically defeats the purpose of OOP design.
I cannot make an OOP design course here, but there are some pretty good references available.
One of the steps I invariably do, when debugging, is comment-out private blocks ... essentially rendering all statements public. Now that I get typing ... and that's just for starters.
Without the essential error code (warning?) accompanying a successful compilation/link/running blank form ... there's little more time expendable for me, especially if you're already running debugger and just don't care to get descriptive enough with words and include a code.
In the mean time I'll looking at usage of "friend".
Don't waste your time, since it will not make any difference. You cannot declare your class to be a friend of some other class in the hope of accessing its private variables. If that was possible then the millions of applications would be open to hacking. Do what I suggested above and make use of the information provided in the documentation: that is what it is there for..
It was serious, actually. If you the designer of the class made a member private then you have two ways to access it: the publicly exposed interface (for instance the get/set methods) or a dirty hack on its bare representation in memory. Typically you cannot use friend because you are not the designer of the class.
"In testa che avete, Signor di Ceprano?"
It looks like you're trying to create a pointer to whatever Run_DDD_OPTION returns. However, you also say
Run_DDD_OPTION(testWidget); // runs fine
which either means that it returns void or you didn't care what it returned. My guess is the former, which would explain all the error messages. If it returns void, you can't take its address, and there is no lvalue (=a memory address).
EDIT: If you want to pass the function Run_DDD_OPTION as an argument to addAction, just write
addAction(tr("&Device Discovery Dialog(modified Bluetooth scanner)"),
You may need the & in front of the function name--I haven't done this in a long time, so I have to look it up. --It looks like it's optional. If it doesn't work without it, try it with it.
I haven't used Qt, so I don't know if I can help. It sounds like a widget is an object, but you're only passing functions and parameters. Would passing an object help?
It's even possible to pass a class's member function[^] as a parameter. I've not used this capability, so you'd have to read up on it if that's what you want.
The problem with passing a function and its parameters is that different functions take different parameters. To deal with that, I think you'd need std::function[^]. Again, that's not something I've used, but now you can look for more details.
My go-to site for C++ is here[^]. It's a bit formal, so sometimes you need to look elsewhere for explanations and examples that are easier to understand. But it will provide you with the right terminology to use when investigating something.
Actually an interviewer asked me this question and told that class C contains the object of B class and through main C obj1(10,20) should be passed. Now you have to write constructor in all three class so that in main() function, it will not give an error.
Last Visit: 31-Dec-99 18:00 Last Update: 19-Jun-21 14:34