I want to read some variables from a .sh file and pass them to an array (maybe better a vector because i won’t know the lengh?). The variables aren’t environment ones, with other words, i’ll set them per hand.
These variables will be global used by the way.
After this I use them to set a command-, icon- and a namelist for a QListWidget.
I i select an item and click a button it executes the command and displays the result in an QTextEdit.
–> You can see the code here. <–
How can i achieve this and is there a better solution?
EDIT:
Im sorry, but english isn’t my native language so its hard to explain …
At first the files which are:
Dialog.h, Dialog.cpp and Dialog.ui
Then the Files which contains the function:
Query.h and Query.cpp
At least the Script wich i call variables.sh for example.
It contains something like this:
CmdList=("kcmshell4 --list|grep -q kcm_grub2",
"kcmshell4 --list|grep -q kcm_networkmanagement",
"which pastebunz",
"[ -z $ink3_ver ]")
NameList=("kcm_grub2",
"kcm_networkmanagement",
"pastebunz",
"Shellmenu")
IconList=(":/icons/icons/GNU.png",
":/icons/icons/networkmanager.png",
":/icons/icons/edit-paste.png",
":/icons/icons/menu.png")
I dont know the length or content of these. So i should use QVector right?
The Query function is called via a button from the Dialog Ui.
Now i must read the variables from variables.h (this should be done at programstart …).
for (int i = 0; i < ${#$cmdList[*]}; i++) // where '${#$cmdList[*]}' represents the
{ some magical stuff; } //legth or the $CmdList array written in bash ...
Then i must use some loop in my function in Query.cpp like
QVector<QString> vCmdList;
for (int i = 0; i < vCmdList.size(); i++)
{
vCmdList[i] = CmdList[i];
}
I hope its clearer now because i have no idea how to explain it more precicely.
Thanks for your patience ^^
It would probably be easier to use
QSettingsand an .ini file to store your commands than bash arrays.For example:
With
QSettings::childGroups(), you’ll be able to iterate over all the command names to then read the command and the icon path for each name.