The full code is:
sqlimport.h
{
Q_OBJECT
public:
void run(); //The main thread process
private:
};
class sqlimport : public QThread
{
Q_OBJECT
public:
void run(); //The main thread process
QString outputFile;
private:
QFile outfile;
QTextStream outStream;
};
To copy to clipboard, switch view to plain text mode
sqlimport.cpp
void sqlimport::run()
{
outfile.setFileName(outputFile);
return;
outStream.setDevice(&outfile);
outStream << "Some data here!" << "\n";
outfile.close();
}
void sqlimport::run()
{
outfile.setFileName(outputFile);
if (!outfile.open(QIODevice::WriteOnly | QIODevice::Text))
return;
outStream.setDevice(&outfile);
outStream << "Some data here!" << "\n";
outfile.close();
}
To copy to clipboard, switch view to plain text mode
That's it. If you do:
sqlimport mysubproc;
mysubproc.outputFile = "/data/myfile.sql";
mysubproc.start(); //Run the thread
sqlimport mysubproc;
mysubproc.outputFile = "/data/myfile.sql";
mysubproc.start(); //Run the thread
To copy to clipboard, switch view to plain text mode
The output file is created but QTextStream fails to write the data.
Carlos.
Bookmarks