1

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
desto
  • 19
  • 2
  • Your code works for me prefectlty with both variants. Can you show file contents? Also, if you changed your code from ui to console right after testing your ui example, maybe you'll have to try to remove your build from its folder and fully rebuild an application? – Shtol Krakov May 25 '16 at 09:23
  • Edited original post with Settings.ini file. As for rebuild, I started new project and copied .h .cpp there. And rebuilded as well. – desto May 25 '16 at 10:53
  • Your problem is in `FONTDATA` and `MONOFONTDATA` lines in `@` symbols. – Shtol Krakov May 25 '16 at 11:14
  • Indeed, removing these lines help. Thank you very much. However, is there a way to set these line so, that it is not calling for error. The line is saved in GUI this way Setts->setValue("FONTDATA", this->font()); and read this way QFont mainfont = qvariant_cast(mw->Setts->value("FONTDATA")); – desto May 25 '16 at 11:24
  • I suppose I know the answer is NO, as I need to include QFont to handle the lines, and it requires "gui" for linking which is contrary to console idea. Thanks for help, – desto May 25 '16 at 11:33
  • Well, the `ini` files are deprecated by Microsoft, so you'd better use registry. Anyway, why you should save values from gui application, if you are using console? – Shtol Krakov May 25 '16 at 11:33

0 Answers0