Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Creator Unit Test Project

In Qt Creator, when I create a new Unit Test project it will not build successfully if the full path to the project contains a space.

I've tracked the bug down to the makefile produced by qmake. The makefile contains a line near the top like:

DEFINES = -DUNICODE -DWIN32 -DSRCDIR=\"C:/Users/Smith/Qt Projects/Unit_Tests/\" -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_TESTLIB_LIB -DQT_CORE_LIB -DQT_TESTCASE_BUILDDIR=\"C:/Users/Smith/Qt Projects/Debug_Unit_Tests\"

The quotes in the values for SRCDIR and QT_TESTCASE_BUILDDIR are escaped with backslashes. If I delete the backslashes from Makefile.Debug, then the project will build successfully.

Obviously, I don't want to have manually delete the backslashes every time. I'd also like to avoid a custom build step that removes the backslashes. Because qmake has so many options, I was hoping there was something I could just put in the .pro file that will fix this.

I tried something like DEFINES -= QT_TESTCASE_BUILDDIR. That doesn't work however because QT_TESTCASE_BUILDDIR is not yet defined. testlib apparently adds its own definitions later.

I am using:

  • Visual Studio 2010 SP 1
  • Qt 5.0.2
  • Qt Creator 2.7.0
  • Windows 7

What's the simplest way to get rid of the backslashes?

Edit: This also happens OSX.

like image 269
mjk99 Avatar asked Feb 16 '23 12:02

mjk99


1 Answers

The definitions added by testlib are in testlib_defines.prf which is in:

C:\Qt\Qt5.0.2\5.0.2\msvc2010\mkspecs\features

Change...

DEFINES += QT_TESTCASE_BUILDDIR=\\\"$$OUT_PWD\\\"

...to...

DEFINES += QT_TESTCASE_BUILDDIR=\"$$OUT_PWD\"

The other part is easy. The extra backslashes for SRCDIR come from the .pro file itself. Change...

DEFINES += SRCDIR=\\\"$$PWD/\\\"

...to...

DEFINES += SRCDIR=\"$$PWD/\"

Every time you install a new version of Qt, you'll have to edit the .prf file but that's better than having to edit the makefile every time qmake runs.

like image 78
mjk99 Avatar answered Mar 05 '23 22:03

mjk99