Whoami
Whoami

Reputation: 14418

Rebuilding Qt application does not change the string

Kindly consider me as a fresher in Qt. I have written the following code for the button click event.

void dbCheck ()
{
    db = QSqlDatabase::addDatabase("QSQLITE");

    QString dbPath(QDir::home().path());

    dbPath.append("/Desktop/jk/sample.sqlite");
    qDebug () <<"Path Name is "<<dbPath;
    .......
}

And after some time, I have changed the following line into

dbPath.append("/Desktop/jk/Newsample.sqlite");

When I ran the code, still it prints the previous path i.e. sample.sqlite.

I cleaned the project, and rebuild the same, but no use, still I'm getting the same result. Really weird.

Did I miss something here? How can I rectify this problem? Anything related to do with cache? Kindly advise.

Upvotes: 1

Views: 361

Answers (2)

hyde
hyde

Reputation: 62869

Be careful about mixing in-source builds and "shadow builds". You get in-source build if you go to the source directory, and run qmake and make. On the other hand, Qt Creator by default uses separate build dir, AKA "shadow building", and you can of course do that yourself too. In practice this is done with qmake by creating build dir as sibling of source dir, going there and doing qmake ../myproject to generate makefiles in the shadow build dir.

Now the thing is, make program does not really have this concept of separate build dir, and if you have performed in-source build, then those built files are accessible to make too. Then when you think you're doing shadow build, make finds those built files under source directory and uses those instead of creating new ones.

In case this is the problem, following should help:

Go to the source dir at Qt SDK command prompt, and run

make clean distclean

Note: order is important, distclean will remove any makefiles too so it must be done last. Also replace make with nmake or mingw32-make or whatever you actually use. If that command does not find a makefile, then you probably have not run qmake there and issue is something else, but you can verify this by running qmake to generate the makefiles, and make clean distclean will work.

Alternative to remove extra files, if you use version control (and have not accidentally checked in generated files...) is to use the version control tool to remove all extra files from the version-controlled directory.

Upvotes: 1

NG_
NG_

Reputation: 7181

Please, recheck your environment: do you really clears all? Insure, that you have no *.o, moc_*.cpp, ui_*.h from previous builds. Try to delete .user file and reconfigure your project to make builds to different folder.

Also, you can use concatenations of strings this way:

QString dbPath = QString("%1%2")
        .arg( QDir::home().path() )
        .arg( "/Desktop/jk/Newsample.sqlite" ) );

Offtop, but don't forget about native separators (http://qt-project.org/doc/qt-4.8/qdir.html#separator and http://qt-project.org/doc/qt-4.8/qdir.html#toNativeSeparators) - if you write crossplatform software.

Upvotes: 0

Related Questions