Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QTabWidget->currentWidget() returns NULL
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QTabWidget->currentWidget() returns NULL

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tusharkant15
    wrote on last edited by
    #1

    Hi!, I'm writing a text editor in qt (4.8.5) mainly for learning. I have QTextEdit widgets inside a QTabWidget. However when I go to access the QTextEdit using the currentWidget function it returns a NULL.

    A little snippet:
    _QWidget *current = maintab->currentWidget();
    if(current == NULL)
    qDebug() << "NULL";
    else
    qDebug() << current->metaObject()->className();
    _
    The output that I get is NULL where I'm expecting QTextEdit. I create the widget using:

    maintab->addTab(new QTextEdit(), "New File");

    What am I doing wrong??

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thEClaw
      wrote on last edited by
      #2

      The documentation says the following:

      bq. Returns a pointer to the page currently being displayed by the tab dialog. The tab dialog does its best to make sure that this value is never 0 (but if you try hard enough, it can be).[/quote]

      I guess you tried hard enough, congratulations.

      Did you actively switch to that current widget? Is the whole TabWidget visible including the tabbar and one if its widgets?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tusharkant15
        wrote on last edited by
        #3

        Never mind found the problem. I feel kinda silly.. I was trying to extract qtextedit in a function that is called before any new tabs are even made. Silly me.....

        1 Reply Last reply
        0
        • T Offline
          T Offline
          thEClaw
          wrote on last edited by
          #4

          Two small things to add:

          1. There is a code-tag (last button for me) which would have made your code above a lot easier to read.

          2. It is good habit to edit the title of your threads and put a [Solved] in front once a problem is solved. Would be a lot easier to navigate in here if everybody did that.

          Happy coding! :)

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tusharkant15
            wrote on last edited by
            #5

            Cool, I'll keep that in mind.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved