How to share share widgets pointers with another widgets
I have a kind of video player application written in QT, the idea is that I can click in an video frame and the app will get the coords and color information from this exact pixels, so far so good the application already works as spected, but the thing is that I have a control panel wish has an List Widget that I fill with the information from the frame, to do that I need to have some kind of communication between these two widgets, what I do now is use this method to find the mainWindow:
QWidget* mainwindow;
QWidgetList list = QApplication::topLevelWidgets();
for (int a = 0; a < list.size(); a++)
if (list[a]->objectName开发者_开发知识库() == "MainWindow")
{
mainwindow = list[a];
break;
}
with this I have access to the mainwindow widget and the mainwindow will serve as a bridge to get access to the pointers of another widget, the problem that I see with this approach is that I need to have an get method to every widget I need access.. Another way to do this is to have an set method in the widget and use a parent widget wish has access to the two widgets I'm looking for to set it right, the problem with this is making methods to this in a parent widget wish doesn't have anything to do with the two methods.. So what I'm asking for is what the best or cleaner method to do this? there is some QT-Way to do this? Thanks!
PS: Just to be clear, I'm not talking about SIGNALS and SLOTS, my idea is to use theses, but first I need an pointer to the widget I'm looking for to then connect to it's slots!
You are trying to do it in lower level code, that is why it is awkward. Neither widget has the context of the other.
Just create signal/slots on the two widgets you want to communicate, then have the calling scope connect them after they are created.
精彩评论