Karsten is right that you should make the
QFile
a member of a class instead of using a global instance.
But the real problem is that you have a global instance declared on top and use a local instance with the same name in your
openConnection
function. So the global instance never gets a file name assigned and is never opened.
It should work this way:
#include <qfile>
QFile logfile;
bool Candump::openConnection()
{
QString CandumpFileName = "C:/xamDevelopment/readfiles/P_1.trc";
logfile.setFileName(CandumpFileName);
if (!logfile.open(QIODevice::ReadOnly | QIODevice::Text))
{
logger()->error("Error occured while opening CANdump file");
}
}</qfile>