Saturday, September 24, 2011

Rebuild SQLite driver for Qt in Visual Studio 2010

The default build of SQLite driver in Qt does not have some features such as full text search. You can add the features yourself by rebuilding it. This is how I rebuild using Visual Studio 2010:
  1. Download latest SQLite amalgamation source code from http://www.sqlite.org, eg: http://www.sqlite.org/sqlite-amalgamation-3070800.zip
  2. Run Visual Studio
  3. Click Qt -> Open Qt Project File (.pro)...
  4. Select  the Qt SQLite project, eg: c:\Qt\4.7.4\src\plugins\sqldrivers\sqlite\sqlite.pro
  5. If somehow the project is not opened in Solution Explorer, check the Output window for hints.
  6. In Solution Explorer, open sqlite3.c, right-click on the file tab and select "Open Containing Folder".
  7. Make a backup of that folder.
  8. Extract SQLite source code to that folder, overwriting everything.
  9. Back to Visual Studio.
  10. Right-click sqlite project and click Properties.
  11. Under Configuration, select Debug.
  12. Go to Configuration Properties -> C/C++ -> Preprocessor.
  13. Click "Preprocessor Definitions". Click the down arrow at the far right. Click 
  14. Put whatever SQLite compilation option you want. Here's mine:
    • SQLITE_THREADSAFE=1
    • SQLITE_ENABLE_FTS3
    • SQLITE_ENABLE_FTS3_PARENTHESIS
    • SQLITE_ENABLE_FTS4
    • SQLITE_ENABLE_RTREE
    • SQLITE_ENABLE_UPDATE_DELETE_LIMIT
    • SQLITE_SOUNDEX
  15. Under Configuration, select Release. Visual Studio will prompt you to save. Click "Yes".
  16. Add the same definitions as Debug.
  17. Close any running applications that uses SQLite, such as Qt Assistant.
  18. Rebuild both Debug and Release. Remember to Rebuild, not just Build, Visual Studio may not detect the changes.
  19. If you get error C1033 ("cannot open program database c:\Qt\4.7.4\src\plugins\sqldrivers\sqlite\vc100.pdb"), make sure the folder and files are not read-only.
  20. These files will be created. Check their modified dates to be sure:
    1. C:\Qt\4.7.4\src\plugins\sqldrivers\sqlite\debug\qsqlited4.dll
    2. C:\Qt\4.7.4\src\plugins\sqldrivers\sqlite\release\qsqlite4.dll
  21. IMPORTANT: qssqlite4.dll and qsqlited4.dll may be created in C:\Qt\4.7.4\src\plugins\sqldrivers\sqlite\release (or debug). If this happens, move it to C:\Qt\4.7.4\plugins\sqldrivers\ and overwrite the existing one. When you debug in Visual Studio, the DLL from this folder will be loaded, even though you have copied the SQLite DLL to your project output.


"WARNING: Can't find the Qt version that's associated with this project."

Updated in Sept 2013 for Qt5.

I don't know why. I am always haunted by this whenever I use a new Qt version:
"WARNING: Can't find the Qt version that's associated with this project. Defaulting to <some Qt version> instead. Please assign a valid Qt version to this project in the Qt project settings."

It happens when you are trying to build and you get it in the build Output window. Trying to change the version using Qt Visual Studio Add-in doesn't help.

My workaround:
  1. Open your project file in a text editor. The project file is the one with "vcxproj" extension, eg: AwfulProject.vcxproj
  2. Look for one of these:
    • For Qt4, QtVersion_x0020_Win32
    • For Qt5, Qt5Version_x0020_Win32
  3. Change it to the Qt version you desire, for example:
    • For Qt4, QtVersion_x0020_Win32="4.7.4"
    • For Qt5, Qt5Version_x0020_Win32="5.1.1"
  4. Save the file.
  5. Reopen the project in Visual Studio.
  6. Remember to change other Qt projects that this project depends on.

"Qt version uses an unsupported makefile generator (used: MSBUILD, supported: MSVC.NET)"

Ok, this post is for those who build Qt libraries with Visual C++ and annoyed by this:
"This Qt version uses an unsupported makefile generator (used: MSBUILD, supported: MSVC.NET)"

It may happen when adding your newly built Qt version in Qt Visual Studio Add-in.

Here's a little hack that works for me:
  1. Close Visual Studio.
  2. Run regedit.
  3. Hop to HKEY_CURRENT_USER\Software\Trolltech\Versions
  4. Add a new key named "4.7.4" or whatever version you have.
  5. Under the new key, create a new string "InstallDir" valued with "c:\Qt\4.7.4":
  6. Run Visual Studio
  7. Click Qt -> Qt Options.
  8. The new version should be there.

My particular system:
  • Visual Studio 2010 with SP1
  • Qt 4.7.4 - Instruction to build with Visual Studio 2010 is here
  • Qt Visual Studio Add-in 1.1.9