if( file.exists() ) not working
-
@ query.exec("SELECT * FROM getTracks");
while(query.next())
{
QString tempFiles= query.value(query.record().indexOf("Filepath")).toString();
QFile f( tempFiles );if(f.exists() ) {
......}
......
...
@value in tempFiles is correct
is not working@@ -
Please provide more details on how it "doesn't work". What result did you expect? What result did you get instead?
-
@ QSqlQuery query(sqlDB);
query.exec("SELECT * FROM getTracks");
while(query.next())
{
QString tempFiles= query.value(query.record().indexOf("Filepath")).toString();
QFile f( tempFiles );if( !f.exists() ) { qDebug()<<"iiiffffffffffff"<<query.value(query.record().indexOf("Filepath")).toString(); } else { obj_trackDB.track_id = query.value(query.record().indexOf("id")).toInt();; obj_trackDB.filename = query.value(query.record().indexOf("filename")).toString(); obj_trackDB.subtitle = query.value(query.record().indexOf("trackname")).toString(); obj_trackDB.track_path = query.value(query.record().indexOf("Filepath")).toString(); obj_trackDB.codec = query.value(query.record().indexOf("codec")).toString(); obj_trackDB.size = query.value(query.record().indexOf("filesize")).toInt(); obj_trackDB.frequecny = query.value(query.record().indexOf("frequency")).toInt(); obj_trackDB.bitrate = query.value(query.record().indexOf("bitrate")).toInt(); obj_trackDB.source = query.value(query.record().indexOf("source")).toInt(); obj_trackDB.track_no = query.value(query.record().indexOf("tracknumber")).toInt(); obj_trackDB.duration = query.value(query.record().indexOf("duration")).toInt(); obj_trackDB.artist_id = query.value(query.record().indexOf("artist_id")).toInt(); obj_trackDB.artist_name1 = query.value(query.record().indexOf("artistName")).toString(); track_obj_mapDB.insert(obj_trackDB.track_id, obj_trackDB);//year qDebug()<< "row count ::" << track_obj_mapDB.size(); } }
@
value in tempFiles is correct
is not working
want to skip functioning for those file whose path is not existing in db. -
Let's see if I understood you correctly: f.exists() returns false, and you get the "iiiffffffffffff" output. Is that correct?
If so, I'm guessing that your tempPath is a relative path, and your application is in the wrong directory. Call this to check:
@qDebug() << QDir::currentPath()@If the directory is wrong, use "QDir::setCurrent()":http://qt-project.org/doc/qt-4.8/qdir.html#setCurrent to go to the correct directory.
-
got id dear.have a nice day