I replaced #define with bool as suggested (note: why this doesn't work?)


if (system("which kchmviewer > /dev/null") == 0)
{
    // "which kchmviewer" exit code 0
    bool useKchmviewer = true;
}
else
{
    // "which kchmviewer" exit code 1
    bool useKchmviewer = false;
}


but the compilation was terminated with the following message (screenshot):

warning: unused variable ‘useKchmviewer’ [-Wunused-variable]

Based on what I read on the Internet (I need to declare a variable first, then I can change the value later), I tried a different approach (note: while this seems to work, I would also like to know how to do this, if possible, using an if…else statement as pointed out above):


bool useKchmviewer = false;

if (system("which kchmviewer > /dev/null") == 0)
{
    // "which kchmviewer" exit code 0
    useKchmviewer = true;
}


This worked, however once I tried to use this with


if (!useKchmviewer)
{
    const QString name = "UserManual";
    const QString suffix = "pdf";
}
else
{
    const QString name = "VirtualBox";
    const QString suffix = "chm";
}


the compiler was unhappy again (screenshot). Based on the answer from Stack Overflow, I altered this code too (note: why is this necessary?):


QString name = "UserManual";
QString suffix = "pdf";

if (useKchmviewer)
{
    name = "VirtualBox";
    suffix = "chm";
}


After this, the compilation finished successfully and the changes worked as expected. However, I still need to adapt other parts of the code so this is only a partial success.

P.S.: I understand how frustrating can be to help a person that doesn't have any knowledge in the topic he/she's expecting to get help in, but please bear with me.

Reply via email to