1

I need to get list of UI elements on the application main window (all windows, doesn't matter). The problem is that there is no topLevelWidgets() function in QGuiApplication, it is in QApplication. Of course I could use QApplication instead of QGuiApplication, but the application already exists and I can't change source codes. I'm writing plugin.

I think if Qt allows you to write place UI elements for application using QGuiApplication class, it should give some way to get those elements, but maybe I'm wrong.

Any ideas?

incognito
  • 457
  • 5
  • 19
  • What is with QWindowList QGuiApplication::topLevelWindows()? If you get a list of the top windows? – Matthias Jul 10 '14 at 09:10
  • I can get topLevelWindows, but it doesn't give me list of UI elements (buttons, text boxes and so on...), it gives me pointer to my window and that's it. – incognito Jul 10 '14 at 09:22
  • This Example is not working... The docs explain this: QApplication specializes QGuiApplication with some functionality needed for QWidget-based applications. It handles widget specific initialization, finalization, and provides session management. – Matthias Jul 10 '14 at 10:29
  • Yes. It appears that you cannot create widgets without creating QApplication. The application I had was using QGuiApplication, but it was using `QQuickView` and `QML`, which is OpenGL actually, not widgets as `QDeclarativeView`. Thanks everybody. – incognito Jul 10 '14 at 11:13

1 Answers1

1
 QList<QWidget *> widgets = centralWidget::findChildren<QWidget *>();

This will get all of the widgets of the MainWindow.

reggie
  • 626
  • 3
  • 13
  • 31
  • As far as I understood centralWidget is a property of `QMainWindow` class. I don't have a pointer to `QMainWindow`. All I have is the pointer to `QGuiApplication` and I need to get all UI elements on the window or widget or whatever is used. – incognito Jul 10 '14 at 09:25
  • change the centralwidget to the name of your qguiapplication. – reggie Jul 10 '14 at 09:28
  • Actually it appears that I can't create widgets for QGuiApplication. That's strange, it doesn't work for my example. I need to check the source codes for the application once again. – incognito Jul 10 '14 at 09:33
  • 1
    Anyway, this answers my question regarding getting widgets from QGuiApplication. Thanks. – incognito Jul 10 '14 at 11:13