2

I work on a C++ application using Qt 5.1.0. We have a main window and several Dock Widgets. These can be put in the left main window area. If several widgets are put in that area, they become tabbed. These tabs are controlled by a QTabBar which I think is implicitly created by the main window.

For testing purposes (we test the application using Squish) I now have the need to give this QTabBar an object name. How do I get a hold of the QTabBar so that I can name it?

Perkulator
  • 21
  • 1
  • 1
    Did you try to find it among main window's child widgets? – vahancho Feb 25 '14 at 07:51
  • Sure, but there will be one QTabBar for each dock area. How do I know which one is which then? – Perkulator Feb 25 '14 at 09:04
  • Does it matter which one is which? You can assign the random names to them, i.e `tab_1`, `tab_2`, etc., and I think Squish will handle such naming pretty well. – vahancho Feb 25 '14 at 09:10
  • So you mean that I can be sure the QTabBars will always be in the same order in the list returned by: mainWin->findChildren(QRegExp("*"), Qt::FindDirectChildrenOnly) – Perkulator Feb 25 '14 at 09:32
  • The order depends on the objects' creation order, so if it does not chenge, the list of children will be stable. But out of curiosity, doesn't Squish handle such windows? I think you can even avoid naming them, because Squish uses property based identification of widgets. – vahancho Feb 25 '14 at 09:43
  • 1
    I've now added code that iterates over my QMainWindow children() and then names all non-named QTabWidgets MainWindowTab-00, MainWindowTab-01 and so on. I'm not entirely convinced that this approach is stable though, since I've been able to find no guarantee that the order of the QTabWidgets in the children list will remain the same. I'll write here again if the solution turns out to be unstable. Thank you for the help! – Perkulator Feb 25 '14 at 12:30
  • Squish can give the tab a symbolic name, but it turns out that the only property that differs between the QMainWindow's QTabBars is a property called occurrence (value 0, 1 and so on). This changes depending on what I do in the application for each test case. Since I want to refer to the QTabBar from scripts used by many test cases it is not good enough. If you have a good solution to that issue in the Squish domain instead, I'm very interested. – Perkulator Feb 25 '14 at 12:38

0 Answers0