I would like to have file in my Qt C++ project that holds all global variables.
Something like: mainvar.h
That I could include in the files where I need access to the globals.
They would hold constants where my settings file is, where I can find the stylesheet and other stuff.
At the moment I have a header file but get the Linker Error: LNK2005 for double definition.
Then, there is #define and extern ...
What's the most modern solution for this and how should I approach this ? The thing is, I dont know yet how many global variables I am going to have.
I come from PHP and things are slightley different over there. Looking forward to your help.
Edit1 :
OK, after the comments, here is some code: I have ejected the old code, so this is holding already the code from the first comment to create a Class:
QFile settingsFile(GlobalSettings::getSettingsFileStr());
if (!settingsFile.exists())
{
//create the settings file
settingsFile.open(QIODevice::ReadWrite);
settingsFile.close();
loadSettings("://src/settings_default.ini");
}
else
{
loadSettings("");
}
In this Setting file I have saved weather a TrayIcon is shown or not when the user closes the application.
Later I want to use this setting in the MainWindow Class. Such as:
QSettings settings(GlobalSettings::getSettingsFileStr(), QSettings::IniFormat);
if ( settings.value("general/trayIcon").toBool() )
{
event->ignore();
showTrayIcon();
this->hide();
}
I hope the edit adds clarity.
All the best, Richard