Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qt "resource" string

Tags:

string

qt

I am wanting to have a place where i can store all the strings used in my applicaton, so i can modify them in one place and not all the places. Something like a resource file, where i can put a label on the strings and just call the label.

I am not aware of anything offered by QT for this, so would I just need to create a header file with all those strings and include it everywhere I need it? What is the appropriate way to do this and could you offer a small example?

Thanks!!

like image 426
prolink007 Avatar asked Jun 05 '11 16:06

prolink007


People also ask

How do I add a resource to Qt?

In the Location field, specify a location for the file. Select Add to create a . qrc file and to open it in the Qt Resource Editor. To add resources to the file, select Add > Add Files.

What is a Qt resource file?

The Qt resource system is a platform-independent mechanism for storing binary files in the application's executable. This is useful if your application always needs a certain set of files (icons, translation files, etc.) and you don't want to run the risk of losing the files.

What is RCC in Qt?

The rcc tool is used to embed resources into a Qt application during the build process. It works by generating a C++ source file containing data specified in a Qt resource (. qrc) file.


1 Answers

I haven't used it yet, but I think, that the Qt Internationalization would allow you to do something like this, since one of it's options is to take all strings out of the application code so they can be replaced by translations. Even if you don't want to use any other features of this module, it would allow you to solve your problem. Replacing a string for a label would look like this:

QLabel *label = new QLabel(tr("Password:"));

The tr() function is already part of the Qt classes and you get a few more functions and macros for free that help to search and replace strings. The strings to be replaced can then be managed with QtLinguist. You can find a more detailed explanation here: Internationalization with Qt

like image 154
thorsten müller Avatar answered Oct 22 '22 17:10

thorsten müller