Reputation: 1620
I'm trying to upload a .avi file to an FTP server with QFtp:
void MyFTP::recordingDone(QString &fileName){
remainingFiles.push_back(new QString(fileName));
commands[qftp.connectToHost(globalProperties.ftpServer)] = "connect to host";
commands[qftp.login(globalProperties.ftpUsername,globalProperties.ftpPassword)] = "login";
commands[qftp.cd("myapp")] = "cd myapp";
commands[qftp.cd("Videos")] = "cd videos";
QDir().cd(globalProperties.videoStorageLocation);
qDebug()<<"Opening "<<fileName<<endl;
if(QFile::exists(fileName)){
qDebug()<<"File exists"<<endl;
}
else{
qDebug()<<"File does not exist"<<endl;
}
QFile file(fileName);
qDebug()<<"putting"<<endl;
qftp.put(&file,fileName);
qDebug()<<"Closing ftp"<<endl;
qftp.close();
}
I'm connected to the command done signal and using the slot to debug output info:
void TrusionFTP::ftpCommandDone(int id, bool error){
qDebug()<<"command: "<<commands[id]<<": "<<error;
if(error){
qDebug()<<qftp.errorString()<<endl;
if (qftp.hasPendingCommands()){
qDebug()<<"Pending commands"<<endl;
}
}
}
Here's the output before the crash:
Opening "2012-Mar-06-12-19-57.avi"
File exists
putting
Closing ftp
command: "connect to host" : false
command: "login" : false
command: "cd trusion" : false
command: "cd videos" : false
The crash also occurs if I don't close the ftp connection. The file never makes it onto the server.
Upvotes: 0
Views: 419
Reputation: 34625
QFile file(fileName);
ids.push_back(qftp.put(&file,fileName));
file
resides on stack. The life time of file
ends as soon as the member function void MyFTP::recordingDone(QString &fileName)
returns. But the qftp
has still reference to it. This is probably causing you the crash when you are trying to access file
which no longer exists. Allocate file
on heap instead.
Upvotes: 5