Particular case of ini file : new elements in QMap and Enum from another file

81 views Asked by At

I' was seen other solutions here, but those solution suggest to modify the file containing the main enum and QMap of a ini file.

So, here the problem : I'm working in QT (C++) about a software's plugin because I must not change anything on the software's code.

on the software's files, there are, for ini file, an enum and a QMap on a file called ini.h and ini.cpp

on non-modifiable ini.h (I modified as cards for clarity):

class CORE_LIBRARY_API Config : public QObject
{ 
  Q_OBJECT

  enum Key 
  {
  // General
  Version,
  // Cards
  King,
  Queen,
  Jack
  }
 ...

on non-modifiable ini.cpp :

inline const QMap<Config::Key, QString> sKey 
{
  // General
  { Config::Version,            "Version"                   },
  // Cards
  { Config::King,               "Cards/King"                },
  { Config::Queen,              "Cards/Queen"               },
  { Config::Jack,               "Cards/Jack"                }
}
...

I want to add from another files the Knight and the Joker on modifiable plugin from ini file : What I do actually, of course, that don't work, the plugin don't read Joker or Knight's value actually...

on modifiable ftarot.h :

class FTarot : public Plugin
{ 
  Q_OBJECT
  enum Key 
  {
  // TarotCards
  Joker,
  Knight
  }
 ...

on modifiable ftarot.cpp :

inline const QMap<FTarot::Key, QString> sKey 
{
  // TarotCards
  { FTarot::Joker,               "TarotCards/Joker"            },
  { FTarot::Knight,              "TarotCards/Knight"           }
}
...

of course, I can modifie the .ini file so here it is:

[General]
Version=x.x.x
[Cards]
King=3
Queen=3
Jack=1
[TarotCards]
Joker=8
Knight=2

So... is there are a problem about what I do here ? Or I must take a deeper look on the Initialization where there are the QSetting part ?

(The non-modifiable QSetting on ini.cpp ):

bool Config::init()
{
   ... *(verification part, not important here)*

   QSettings config(sConfigFilePath, QSettings::IniFormat);

   QMetaEnum metaEnum = QMetaEnum::fromType<Key>();

   ... *(verification part, not important here)*
   }
  }
  return *(verificaion ok/nok)*;
}

// This one use the sKey list to take a value "card" from the list cardfound used in case the card wasn't found:
QVariant Config::variant(const Key& card, const QVariant& cardfound)
{
  QSettings config(sConfigFilePath, QSettings::IniFormat);
  return config.value(sKey.value(card), cardfound);
}

Thank you for reading !

0

There are 0 answers