Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-11588

Adding tabs to QTabWidget and infinite recursion

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P2: Important
    • 4.8.x
    • 4.6.2
    • None
    • Ubuntu Linux 10.04

    Description

      In a rather complex situation with some meta-programming I ended up doing something that is the equivalent of this:

      #include <QtGui>

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);
      QTabWidget *tw = new QTabWidget();
      tw->addTab( tw, "Doh" );
      tw->show();
      return a.exec();
      }

      Now this will obviously lead to an infinite loop, but it would be nice if the addTab() function would check if you were trying to add itself or one of its parents and stop you. Since it's already retuning an int corresponding to the new tab index, it could fail and return -1. I imagine it could be done with something like:

      int TabWidget::addTab( QWidget *tab, QString &label )
      {
      QWidget *w = this;
      while( w )

      { if ( w == tab ) return -1; w = w.parentWidget(); }

      // Continue as usual
      }

      Maybe even throw in a qWarning that this shouldn't happen or something as well, I don't know the policy on that. But it'd be a lot easier to debug than what I had to just do to figure out what's going on. Infinite recursion is plain nasty and even though this will add a microscopic speed penalty I think it's worth it.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            lscunha Leonardo Sobral Cunha (Inactive)
            kjella Kjell Rune Skaaraas
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes