PDA

View Full Version : TabWidget



Salazaar
17th May 2007, 19:56
Hi. I've got a tab widget created in designer, and I want one of tab to has a name which is typed in some lineEdit.
tab - tekst
lineEdit - tekst

How to do it?

marcel
17th May 2007, 20:05
Create a slot in your main window class, called let's say tabNameChanged( const QString& ).

Connect the line edit's textEdited( const QString& ) to that slot.
The slot implementation:


void MyWindow::tabNameChanged( const QString &text )
{
mTabWidget->setTabText( mTabWidget->currentIndex(), text ).
}


Please note that this is live update and the text is set only in the current tab. You can play a bit with the code to achieve other results ( update other tab, etc ).

Regards

Salazaar
17th May 2007, 20:19
Thanks, and I've got a question about it. What's the currentIndex() ? and why we have to make the function const QString? And where (when) should I call this function?

wysota
17th May 2007, 20:28
Please read the docs. Open Qt Assistant and type in "currentIndex" into the box on the left in the "index" tab. This might clarify some things.

marcel
17th May 2007, 20:35
To wysota:
Open Qt Assistant what is Qt Assistant? :)



and why we have to make the function const QString?

It is not "const QString" but "const QString&". This "const" is there to improve performance - you basically tell the compiler that the QString won't be modified inside the function. Normally, the purpose of passing params by reference is to modify them inside the function and not "stress" the stack too much ( like when passing by value ).

wysota
17th May 2007, 21:07
To wysota: what is Qt Assistant? :)
A funny black box that made me post over 5k times here and over 4k times back at QtForum.


It is not "const QString" but "const QString&". This "const" is there to improve performance
That's a side effect. The true effect is that you forbid any changes to the object.


Normally, the purpose of passing params by reference is to modify them inside the function and not "stress" the stack too much ( like when passing by value ).
It's not stressing the stack but avoiding the need to copy heavy objects for simple operations. With Qt implicit sharing you can pass parameters by value without a noticable slowdown.

But in general all that you say is true and my post was only to answer your first question :)