[Solved] QString::fromLatin1() acting weird with MinGW
-
I have a working app with MSVC. But if I want to make it also work with MinGW I get a strange SIGSEGV fault at one of the char array to string conversions with QString::fromLatin1.
While debugging I've seen that while trying to create a new QString from the array compiler changes the contents of the char array which shouldn't be happening.
Here's the code snippet.
@QString *tstr;
tstr = new QString(QString::fromLatin1(tcharray, -1));
if(*tstr != "5500")
{
delete tstr;
result.code = HAL::HAL_ROR_reader_hardware_error;
}@For example before conversion the array contains { 0x35, 0x35, 0x30, 0x30, 0x00, 0x00 ... } which is the expected data. If I step trough the conversion, the array becomes { 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00 ... } before conversion and then the new string of course contains gibberish chars.
This makes the app flow flawed and gives me SIGSEGV at one point (of course I have to figure it out and prevent it no matter what the array carries).
Why is this conversion acting like that?
As a hint, also the "this" variable also acts weird while running step by step. It carries 0x410058 value at the method start, then before running conversion carries 0x200 (which doesn't look like OK) and after conversion carries 0x28c530. Why's the parent class instance address is changing? I guess it should be fixed while running one of it's method.
Thanks in advance.
/// Murat
-
This sounds like a crooked build. Have you tried cleaning and rebuilding your project? Can you reproduce the same behavior in a minimal example (to exclude the possibility that some other heisenbug is interfering)?
Btw. It's unusual to have heap allocated QString. Qt types are implicitly shared and use a pimpl idiom so using a pointer has little to no benefit here.
Edit: Also, a basic question but worth clearing out - are you using a MinGW build of Qt or did you just switched compilers and keep using the MSVC Qt build/dlls?
-
Yep I tried a clean build but the result was the same. I'll try to reproduce the issue at bare minimum.
To be honest, I used stack for all of the variables before, but somehow I got too many SIGSEGV/0x800000C5 errors. That's why I used more heap method. At least it helped to reduce the exceptions.
By the way, you might be right about another bug since C++ world is a bit new for me.
Edit for Edit:
I've downloaded and installed both MinGW and MSVC builds for Qt. But I'm note sure that I've done everything right.
-
I've tried to reproduce the issue in a very simple console application, but it worked fine. That means there is a really annoying hinden-bug and I have to find it somehow.
Thanks Chris.
-
I've found the guilty part. It's the external DLL a vendor had prepared. Probably it was compiled with MSVC and not compatible with MinGW. It messes up with the rest of the application without showing any obvious sign.