Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED] How would I go about accessing Ui from another function in a different source file?
For example: in this chunk of code:
SOLVED by using simple Signals and Slots implementation. See below.
Rahul Das last edited by
Try @setPlainText ( const QString & text )@
If your tCamera class is separate from the class which contains the Ui, then create a signal in your tCamera class which emits the QString you want to display. In your UI class, create a slot which receives a QString and sets the TextBrowser's text with that screen. Then somewhere outside of both classes, connect that signal to that slot.
Thanks mlong. I really appreciate your input on my other threads as well.
My pleasure! I hope this helps. If so, please edit your first post and add [Solved] to the title. Thanks!
[quote author="mlong" date="1336501102"]If your tCamera class is separate from the class which contains the Ui, then create a signal in your tCamera class which emits the QString you want to display. In your UI class, create a slot which receives a QString and sets the TextBrowser's text with that screen. Then somewhere outside of both classes, connect that signal to that slot.
I've to clarify something about creating the signal. So you how would I create a signal emitting the string? Would it just be something like void sendSignal ("This is a string") ? I suppose if it is implemented this way, the connect function would make "This is a string" a parameter to the slot function, but I was just wondering how a void function with a parameter could transfer information in that way (If I am not misunderstanding anything)
You don't know much about signals and slots, do you? ;) Knowing that stuff is probably one of the most important things you'll need to know to do any substantive work with Qt. I'd insist upon you going through the "documentation":/doc/qt-4.8/signalsandslots.html that covers it. (It's stuff you have to know cold.)
But, in short (though I'm reluctant to spoon feed it...)
you would define a signal such as:
(you don't have to write the implementation of this. It will be autogenerated.)
and to use it in your code you use:
emit mySignal("Whatever text I want to send.");
That signal would ideally be connected to a slot with a compatible signature:
Edit to add:
Since the code for the body of the signal is generated by MOC, the return type of the signal is void. The string you want to pass in is a parameter because the MOC-generated code knows how to take that value passed in as a parameter and poke it into the corresponding parameter in the connected slot.