June 16, 2011

Ruzik Ruzik
Lab Rat
293 posts

How can i get pointer on the widget of current tab in QTabWidget?

 

How can i get pointer on the widget of current tab in QTabWidget?
Advance many thanks fro help!

13 replies

June 16, 2011

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

QTabWidget::currentWidget() [doc.qt.nokia.com]

June 16, 2011

aureshinite aureshinite
Lab Rat
61 posts

Wow do you read the doc??.. [doc.qt.nokia.com]

June 16, 2011

Ruzik Ruzik
Lab Rat
293 posts

I read it before i asked, but on the this code

  1.   tabWidget->addTab(new QPlainTextEdit, "New tab");
  2.  QPlainTextEdit * p = qobject_cast<QPlainTextEdit *>(tabWidget->currentWidget());
  3.   p->setPlainText("dsg");

Compiler get me a error, and thats why i asked you about it

June 16, 2011

Gerolf Gerolf
Robot Herder
3235 posts

which error?

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

June 16, 2011

Ruzik Ruzik
Lab Rat
293 posts

If i change code:

  1.  tabWidget->addTab(new QPlainTextEdit, "New tab");
  2.  QPlainTextEdit * p = qobject_cast<QPlainTextEdit *>(tabWidget->currentWidget());
  3.  if (p)
  4.   p->setPlainText("dsg");

It is work right, but conversion does not occur

June 16, 2011

Ruzik Ruzik
Lab Rat
293 posts

Gerolf wrote:
which error?

Access violation when reading

June 16, 2011

Gerolf Gerolf
Robot Herder
3235 posts

is the new tab the current one? are you sure?

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

June 16, 2011

ludde ludde
Lab Rat
325 posts

A bit hard to see what’s wrong from just those four lines of code.
I assume qssTextEdit is a QPlainTextEdit subclass?
And that you haven’t added any other tabs?
You could always check what tabWidget->currentWidget() actually returns, using a debugger or some form of debug output, e.g. by printing what tabWidget->currentWidget()->metaObject()->className() returns.

June 16, 2011

Ruzik Ruzik
Lab Rat
293 posts

Many thanks for your help – i find error!

June 16, 2011

mlong mlong
Robot Herder
1551 posts

What was it? (For those of us who are keeping score…)

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

June 17, 2011

Ruzik Ruzik
Lab Rat
293 posts

I’m in the designer created a table and a default is already located there QPlainTextEdit and when I addressed him, it is transformed into kvidget, not QPlainTextEdit

June 5, 2013

Qlearner Qlearner
Lab Rat
1 posts

To read the text associated with a tab’s QTextEdit widget ( tab at index x) , I did this

  1.  tabWidget->addTab(new QTextEdit ,"New tab");
  2.  QTextEdit* t= qobject_cast<QTextEdit*>(tabWidget->widget(x));
  3.  qDebug() << t->toPlainText();

Just in case someone still needed it.

June 11, 2013

Vittal Vittal
Lab Rat
47 posts

Hi.. Ruzik

once try this code..

QTabWidget *wd;
tabWidget->addTab(new QTextEdit ,“New tab”);

QList<QTextEdit * > widgets = wd->findChildren<QTextEdit* >();
…..

widgets.at(2) or widgets.at(index)

 
  ‹‹ [SOLVED] ssh connection      Qmake and white spaces in TARGET, DESTDIR, etc... ››

You must log in to post a reply. Not a member yet? Register here!