"Open Project" button does not work with CMake 3.12 rc1 on Windows (compiled with QT4.8.7 / QT5.11)
Compiling CMake 3.12 (release branch) on Win(x64), VS2017, QT4.8.7 or QT5.11
The issue has been tracked down to the following coding construct:
doSomething( someQString.toLocal8Bit().data() );
data() returns a reference to a buffer internal to the temporary QByteArray
returned by toLocal8Bit()
. Once that object is destroyed, the reference is garbage. It appears to depend on the compiler used as to precisely when the destructor is invoked on the temporary object.
One of the replies in this Stackoverflow Question mentions this in this exact usage scenario; the official QT documentation mentions this as well.
The fix is to save the intermediate QByteArray
in a variable to ensure it does not go out of scope for as long as the reference returned by data()
is being used.
auto lstr = someQString.toLocal8Bit();
doSomething( lstr.data() );
While the issue was identified in the QCMake::checkOpenPossible()
, the construct is used in various places and may be the cause of other errors.
A pull request shall be issued shortly to address this.