0

firstly,I have downloaded the libconfig x64-windows via vcpkg like this:

PS E:\vcpkg> .\vcpkg install libconfig:x64-windows

then,I added the lib to my Qt project with three steps

1.add the headfile

#include "libconfig.h++"

2.specify the lib path in the pro file(I have tried two ways)

LIBS += -L$PWD -llibconfig++
#LIBS += libconfig++.lib

3.in the build debug folder,I added the libconfig++.dll

after doing those steps,project was been built successfully without any error.then I added some code like these:

libconfig::Config cfg;
try{

    cfg.readFile("D:\test.cfg");
}
catch(const libconfig::FileIOException&filex) {
    Q_UNUSED(filex);
    qDebug()<<"error";
    return;
}
qDebug()<<"success";

and the output was always :"error",I have done the everything and the Qt window was displayed successfully.Once I called readFile api,it occured an error .

wenjx
  • 11
  • 3

1 Answers1

1

I have got the answer to my issue. The file path in Windows must have the double backslash. So I must switch:

cfg.readFile("D:\test.cfg");

to

cfg.readFile("D:\\test.cfg");
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
wenjx
  • 11
  • 3