Hi,
during debug mode (F5 with default keys) the conversion from QString to char* fails and produces garbage data. That way, I cannot debug my program properly. When running my program normally (Ctrl+R) it's working just fine.
Below you will find a small example, that determines the type of drives in Windows. I tested with Qt 5.5.1 and Qt 5.4.2. Qt Creator is at version 3.6.1.
#include <iostream>
#include <windows.h>
#include <winbase.h>
#include <QtCore>
using namespace std;
int main(void)
{
QFileInfoList localDrives
= QDir::drives();
{
const char *drive
= QDir::toNativeSeparators(info.
path()).
toStdString().
c_str();
UINT drivetype = GetDriveTypeA(drive);
qDebug
() << info.
path().
left(1) <<
QString::fromLocal8Bit(drive
) <<
"is" << drivetype;
}
return 0;
}
#include <iostream>
#include <windows.h>
#include <winbase.h>
#include <QtCore>
using namespace std;
int main(void)
{
QFileInfoList localDrives = QDir::drives();
for (QFileInfo info : localDrives)
{
const char *drive = QDir::toNativeSeparators(info.path()).toStdString().c_str();
UINT drivetype = GetDriveTypeA(drive);
qDebug() << info.path().left(1) << QString::fromLocal8Bit(drive) << "is" << drivetype;
}
return 0;
}
To copy to clipboard, switch view to plain text mode
Here is the output during debug mode. Of course, GetDriveTypeA(...) returns always 1 here. Sh*t in, sh*t out.
Debugging starts
"C" "««««««««îþîþ\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000ma?\u0003OÇ\u0000\u0018\u0001ð\u00ADº\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000««««««««\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000la?\u0002OÇ\u0000\u001CÈ\u00ADÆk««««««««îþîþ\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000la?\u0002NÇ\u0000\u0018ȬÆk\u0001\u0000\u0000\u0000««««««««\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000ka<\u0006NÇ\u0000\u0000\u0010G€\u0000P\u0019€\u0000îþîþîþîþla?\u0002IÇ\u0000\u0018ȬÆk\u0000\u0000\u0000\u0000««««««««\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000ma?\u0003NÇ\u0000\u001C(¼Æk\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0000««««««««îþîþ\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000na?\u0000OÇ\u0000$(¼Æk\u0003\u0000\u0000\u0000\u0000\u0000\u0000\u0000««««««««îþîþîþîþîþîþ\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000la?\u0002LÇ\u0000\u0018ȬÆk\u0002\u0000\u0000\u0000««««««««\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000la?\u0002NÇ\u0000\u0018ȬÆk\u0003\u0000\u0000\u00ò¥êBio
"D" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"E" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"F" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"G" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"I" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"P" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"Q" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"R" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"W" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
Debugging has finished
Debugging starts
"C" "««««««««îþîþ\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000ma?\u0003OÇ\u0000\u0018\u0001ð\u00ADº\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000««««««««\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000la?\u0002OÇ\u0000\u001CÈ\u00ADÆk««««««««îþîþ\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000la?\u0002NÇ\u0000\u0018ȬÆk\u0001\u0000\u0000\u0000««««««««\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000ka<\u0006NÇ\u0000\u0000\u0010G€\u0000P\u0019€\u0000îþîþîþîþla?\u0002IÇ\u0000\u0018ȬÆk\u0000\u0000\u0000\u0000««««««««\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000ma?\u0003NÇ\u0000\u001C(¼Æk\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0000««««««««îþîþ\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000na?\u0000OÇ\u0000$(¼Æk\u0003\u0000\u0000\u0000\u0000\u0000\u0000\u0000««««««««îþîþîþîþîþîþ\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000la?\u0002LÇ\u0000\u0018ȬÆk\u0002\u0000\u0000\u0000««««««««\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000la?\u0002NÇ\u0000\u0018ȬÆk\u0003\u0000\u0000\u00ò¥êBio
"D" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"E" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"F" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"G" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"I" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"P" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"Q" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"R" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
"W" "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþoa?\u0001VÇ" is 1
Debugging has finished
To copy to clipboard, switch view to plain text mode
And here's the output from normal run:
Starting D:\Andreas\Qt\build-StringTest-Desktop_Qt_5_5_1_MinGW_32bit2-Debug\debug\StringTest.exe...
"C" "C:\\" is 3
"D" "D:\\" is 3
"E" "E:\\" is 5
"F" "F:\\" is 2
"G" "G:\\" is 2
"I" "I:\\" is 3
"P" "P:\\" is 5
"Q" "Q:\\" is 5
"R" "R:\\" is 5
"W" "W:\\" is 3
D:\Andreas\Qt\build-StringTest-Desktop_Qt_5_5_1_MinGW_32bit2-Debug\debug\StringTest.exe exited with code 0
Starting D:\Andreas\Qt\build-StringTest-Desktop_Qt_5_5_1_MinGW_32bit2-Debug\debug\StringTest.exe...
"C" "C:\\" is 3
"D" "D:\\" is 3
"E" "E:\\" is 5
"F" "F:\\" is 2
"G" "G:\\" is 2
"I" "I:\\" is 3
"P" "P:\\" is 5
"Q" "Q:\\" is 5
"R" "R:\\" is 5
"W" "W:\\" is 3
D:\Andreas\Qt\build-StringTest-Desktop_Qt_5_5_1_MinGW_32bit2-Debug\debug\StringTest.exe exited with code 0
To copy to clipboard, switch view to plain text mode
What could be the problem and can I do something to solve it?
Merci.
Bookmarks