Sunday, January 9, 2011

Delete a folder in Qt

This code snippet allows programmer to delete a folder in Qt

#include <QDir>

void deleteDir(const std::string& foldername)
{

  QDir dir;
  dir.rmdir(foldername.c_str());
}

List directories in Qt

This code snippet allows programmer to list directories in a parent directory "C:\temp" by using Qt API

#include <QDir>

void list(QStringList& dirnames)
{

         QDir currentDir("C:\\temp");

currentDir.setFilter(QDir::Dirs);
QStringList entries = currentDir.entryList();
for( QStringList::ConstIterator entry=entries.begin(); entry!=entries.end(); ++entry )
{
//std::cout << *entry << std::endl;
QString dirname=*entry;
if(dirname != tr(".") && dirname != tr(".."))
{
dirnames.add(dirname);
}
}
}

Monday, January 3, 2011

The procedure entry point _Z5qFreePv could not be located in the dynamic link library qtCore4.dll

To remove the issues with release build issue error "The procedure entry point _Z5qFreePv could not be located in the dynamic link library qtCore4.dll":
  1. Track down the source of the dll using depends.exe (downloadable from http://www.dependencywalker.com/)
    • Source of Problem 1: debug version of an app exe compiled and opened fine, release version of same app would compile fine but exe failed due to "entry point" in dll failure. There are some old QtCore and QtGui dll's in System32 directory.
    • Solution 1: The release version was referencing these dll's. I removed them.
    • Source of Problem 2: the QtCore.dll referenced is pointed to "C:\Qt\2009.02\bin" instead of "C:\Qt\2009.02\qt\bin"
    • Solution 2: remove "C:\Qt\2009.02\bin" from the path environmental variables

Totally remove Symbian SDK for Qt to use its make

The "make" error is quite annoying when you previously install Symbian SDK and now want to use Qt for build as the make tool will be set to that of  Symbian SDK instead of the Qt make. To remove the problem of "make" with the previous installation of symbian SDK:
  1. go to the global environmental variables
  2. go to the system variables, remove "C:\Program Files\Common Files\Symbians\Tools\..." from the "Path" variable

Print to console in Qt

To print to console in Qt
  1. write the code the usual console output way, e.g. "std::cout << ...", Note that any QString object must be quoted inside "qPrintable" function, e.g. "std::cout << qPrintable(QString("hello")) << .."
  2. enter "qmake -project"
  3. add "CONFIG += console" to the xxx.pro file
  4. enter "qmake"
  5. enter "make"

Sqlite in Qt

To connect to the Sqlite database in Qt
  1. add "#include "
  2. add "QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE")" in the code body
  3. enter "qmake -project"
  4. add "QT += sql" in the xxx.pro file
  5. enter "qmake"
  6. enter "make"

Regular Expression Replacement in Visual Studio

Text replacement in visual studio using Regular Expression can be very handy during refactoring in large projects.

E.g. to find "new DoubleFieldEntry(Convert.ToString(_obj.[Text to Keep]));" and replace with "new DoubleFieldEntry(_obj.[Text to Keep]);"

The find regular expression is "new DoubleFieldEntry\(Convert.ToString\({_obj.*}\)\);" and the replace regular expression "new DoubleFieldEntry\(\1\);"


The above replacement in the figure replaces codes in the current project such as "new IntFieldEntry(Convert.ToString(_obj.SaleID))" to "new IntFieldEntry(_obj.SaleID)"