I am using Qt and I need some help
-
How to declare
QStringListvariable globally in Qt so that I can access it in any function? -
How to print all the stuff in
QStringList(it contains the file path which it took fromQFileDialog) to alineEdit?
I tried:
ui->lineEdit->setText(filename);
But it gave me error error:QString to non-scalar type QStringList requested.
Please give me some examples.
Well this isn’t a
Qtquestion, but a general C++ one (global variables are frowned upon these days, a more acceptable equivalent is the singleton, search SO for lots of examples). Nonetheless, one way of doing this would be create theQStringListas a static member of the class that instantiates theQFileDialog, the same class will be the one that retrieved it from the dialog anyway and by storing (and returning) it statically you effectively make it global:Well, if your
QStringListonly contains one string just use:Remember a
QStringListis derived fromQVector< QString >, so you can access the individualQStrings just like any element.Just to expand your first question, there an infinite number of ways a list of strings can be combined into a single one. But a very common (and easy) method with
QStringListis to usejoin():I really recommend using the docs, Qt’s are brilliant .