PDA

View Full Version : Qfile and QDebug help



sgoten
19th July 2012, 05:41
hi I am new to qt and I was following this tutorial and got everything right but I keep getting error's can any one help


#include <QtGui/QApplication>
#include <QFile>
#include <QString>
#include <QtDebug>
#include <QTextStream>


void write(QString filename){
QFile myfile(filename);

if(!(myfile.open(QFile::WriteOnly | QFile::Text))){

qDebug()<<"Could not write to file ";
return;
}
QTextStream out(&myfile);
out<<"hello world";

myfile.flush();
myfile.close();

}

void read(QString filename){
QFile myfile(filename);

if((myfile.open(QFile::ReadOnly | QFile::Text))){

qDebug()<<"Could not read file";
return;

}

QTextStream in(&myfile);
qDebug()<< in.readAll();
myfile.close();


}


int main(int argc, char *argv[]){
QApplication app(argc,argv);

QString myfile = "c:/qt/tet.txt";

write(myfile);
read(myfile);
return app.exec();
}

augusbas
19th July 2012, 06:34
What was the error with the above code ....You haven't mentioned it..

sgoten
19th July 2012, 06:52
these are the issues that show up

In function `main':
undefined reference to `_imp___ZN12QApplicationC1ERiPPci' main.cpp line 41
undefined reference to `_imp___ZN12QApplication4execEv' main.cpp 47
undefined reference to `_imp___ZN12QApplicationD1Ev' main.cpp 47
undefined reference to `_imp___ZN12QApplicationD1Ev' main.cpp 47

augusbas
19th July 2012, 07:12
Refer the below links ...Hope that helps

http://qt-project.org/forums/viewthread/2098

http://www.qtcentre.org/archive/index.php/t-30962.html

ChrisW67
19th July 2012, 09:47
What does your PRO file look like?