Qt Creator Unit Test Project

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

I tracked the error to the make file created by qmake. The make file contains a line near the top, for example:

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 for SRCDIR and QT_TESTCASE_BUILDDIR reset with QT_TESTCASE_BUILDDIR . If I remove the backslash with Makefile.Debug , the project will succeed.

Obviously, I don't want to manually remove the backslash every time. I would also like to avoid a custom build step that removes the backslash. Since qmake has so many options, I was hoping there was something that I could just put in a .pro file that would fix this.

I tried something like DEFINES -= QT_TESTCASE_BUILDDIR . However, this does not work as QT_TESTCASE_BUILDDIR is not yet defined. testlib seems to add its own definitions later.

I use:

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

What is the easiest way to get rid of backslashes?

Edit: This also happens with OSX.

+4
source share
1 answer

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

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

Edit ...

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

... before...

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

The other part is simple. Additional backslashes for SRCDIR come from the .pro file itself. Edit ...

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

... before...

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

Each time you install a new version of Qt, you need to edit the .prf file, but this is better than having to edit the make file every time qmake starts.

+8
source

Source: https://habr.com/ru/post/1481398/


All Articles