Hi, everyone. I am studying Qt4. I want to write a function that reads from a file and the write to the same file. It is supposed to be simple, but I can't make it through the compiler.
Here is my header file:
#include <QFile>
#include <QString>
#include <QStringList>
#include <QTextStream>
class rwFile
{
private:
static QFile sm_fileData;
public:
rwFile(QString fileName);
QStringList readFile();
void writeFile(QStringList LstData);
};
Here is my cpp file:
rwFile::rwFile(QString fileName)
{
sm_fileData(fileName); // ***Error here!!
}
QStringList rwFile::readFile()
{
QStringList LstLines;
sm_fileData.open(QIODevice::ReadOnly);
QTextStream readData(&sm_fileData);
while (!readData.atEnd())
{
LstLines << readData.readLine();
}
sm_fileData.close();
return LstLines;
}
void rwFile::writeFile(QStringList LstData)
{
sm_fileData.open(QIODevice::WriteOnly);
QTextStream writeData(&sm_fileData);
foreach(QString data, LstData)
{
writeData << data << endl;
}
sm_fileData.close();
}
The error message (in the line marked by *** in my cpp file) is "no match for call to ‘(QFile) (QString&)’".
Could anybody help me with this class? Thanks