Qt 5.5.0
I'm switching one of my gui applications to console. I'm having a problem with QSettings object initiation in console mode.
This is the code in gui, it works fine:
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
QSettings *Setts; //settigns
...
}
MainWindow::MainWindow()
{
QFile setfile("./SA/Settings.ini");
if (setfile.exists())
setfile.setPermissions(setfile.permissions() | QFileDevice::ReadUser | QFileDevice::WriteUser);
Setts = new QSettings("./SA/Settings.ini", QSettings::IniFormat);
setfile.setFileName(Setts->value("Localization","./SA/en.loc").toString());
...
}
int main(int argc, char *argv[])
{
QPointer<QApplication> app;
QPointer<MainWindow> main_window;
app = new QApplication(argc, argv);
main_window = new MainWindow();
...
}
and this is code for console
class MainWindow : public QObject
{
Q_OBJECT
public:
MainWindow();
~MainWindow();
QSettings *Setts; //settigns
...
}
MainWindow::MainWindow()
{
QFile setfile("./SA/Settings.ini");
if (setfile.exists())
setfile.setPermissions(setfile.permissions() | QFileDevice::ReadUser | QFileDevice::WriteUser);
Setts = new QSettings("./SA/Settings.ini", QSettings::IniFormat);
setfile.setFileName(Setts->value("Localization",QString("./SA/en.loc")).toString());
...
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MainWindow mw;
...
}
Console code fails over calling Setts->value with the error: ASSERT failure in QVariant: "Trying to construct an unknown type", file kernel\qvariant.cpp, line 980.
While debugging I noticed warnings when I enter class constructor: can't find linker symbol for virtual table for `QSettings' value.
I tried multiple ways, QSettings doesn`t initialize values in its constructor, though the file is present. Calling Setts->contains("Localization") also gives the same error. But if I use Setts->setValue after constructor, it works fine. What can I do to make QSettings initialize in constructor?
Settings.ini
[General]
geometry="@ByteArray(\x1\xd9\xd0\xcb\0\x2\0\0\0\0\aw\xff\xff\xff\xf7\0\0\xf\b\0\0\x4\x10\0\0\bn\0\0\0\x43\0\0\f\x8c\0\0\x4;\0\0\0\x1\x2\0\0\0\a\x80)"
Localization=./SA/ru.loc
LOCALE=Windows-1251
CONSOLELOCALE=csIBM866
LOGFILE=./SA/log.txt
SETNUMBER=basic
COMPORT=COM1
STATUS=false
CONSOLE=true
FILE=false
TIME=true
DIRECTION=true
FONTDATA=@Variant(\0\0\0@\0\0\0\x1c\0M\0S\0 \0S\0h\0\x65\0l\0l\0 \0\x44\0l\0g\0 \0\x32@ \0\0\0\0\0\0\xff\xff\xff\xff\x5\x1\0\x32\x10)
MONOFONTDATA=@Variant(\0\0\0@\0\0\0\x10\0\x43\0o\0n\0s\0o\0l\0\x61\0s@ \0\0\0\0\0\0\xff\xff\xff\xff\x5\x1\0\x32\x10)
AUTOCLEAR=true
AUTODETAILS=true
ACKTIMEOUT=5
NAKTIMEOUT=2
MSGTIMEOUT=45