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?
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?
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:
Qt Code:
{ mTabWidget->setTabText( mTabWidget->currentIndex(), text ). }To copy to clipboard, switch view to plain text mode
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
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?
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.
To wysota:what is Qt Assistant?Open Qt Assistant
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 ).and why we have to make the function const QString?
A funny black box that made me post over 5k times here and over 4k times back at QtForum.
That's a side effect. The true effect is that you forbid any changes to the object.It is not "const QString" but "const QString&". This "const" is there to improve performance
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.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 ).
But in general all that you say is true and my post was only to answer your first question
Bookmarks