You mean that should i restart the program if I want to gets update
No. No. If you have set the original label name "Favorite1" using Qt Designer and save that in a .ui file, then ever time the program runs, it will set the label to "Favorite1" because that's what the .ui files says. If you allow the user to change the label, and you want the new label text to appear the next time the user runs the program, then you need to save the new name in a configuration file (using QSettings). The next time the program runs, you must read the configuration file (using QSettings) and get the new value for the label, and then set it using code, something like this:
{
// Open the configuration INI file
// Read the value the user has set for the label text. If it is not found, then use the default text set by the ui file
QString labelText
= settings.
value( "LabelText",
QVariant( myLabel
->text
() ).
toString();
// Change the label to show the new text
myLabel->setText( labelText );
}
void MyWidget::showEvent( QShowEvent * ev )
{
// Open the configuration INI file
QSettings settings( "MyConfigFile.ini", QSettings::IniFormat );
// Read the value the user has set for the label text. If it is not found, then use the default text set by the ui file
QString labelText = settings.value( "LabelText", QVariant( myLabel->text() ).toString();
// Change the label to show the new text
myLabel->setText( labelText );
}
To copy to clipboard, switch view to plain text mode
I mean just changing the label name in 1 screen (or one class), but same name should appear in another class immediately (may be in another class).
I have no idea what you mean by this. A "class" is C++ code. You can't change code at runtime. If you mean you have two widgets with a label on them, and you want the same text to appear in both places when it is edited, then just change the text for the second label at the same time you change the text for the first one:
myLabel1
->setText
( QInputDialog::getText( this,
"Label Editor",
"Enter the new label text:",
QLineEdit::Normal, myLabel1
->text
() );
myLabel2->setText( myLabel1->text() );
// Open the configuration INI file
// Save the value the user has set for the label text.
settings.
setValue( "LabelText",
QVariant( myLabel
->text
() );
myLabel1->setText( QInputDialog::getText( this, "Label Editor", "Enter the new label text:", QLineEdit::Normal, myLabel1->text() );
myLabel2->setText( myLabel1->text() );
// Open the configuration INI file
QSettings settings( "MyConfigFile.ini", QSettings::IniFormat );
// Save the value the user has set for the label text.
settings.setValue( "LabelText", QVariant( myLabel->text() );
To copy to clipboard, switch view to plain text mode
Bookmarks