TDobmeye

I am trying to convert a QString to a std:Tongue Tiedtring using VS 2005 and Qt 4.3.0. There is a function in QString::toStdString( ) that returns a std:Tongue Tiedtring and I have used this many times when I used VS 2003 and Qt 4.3.0 but I was recently forced to upgrade to VS 2005. Now I have been crashing in a function and I have narrowed it down to this call. I have commented out everything but this one line for code that looks like:

Code Snippet

std::string sname = selected.toStdString( );

Whenever I try to leave this function that only has one line of executed code (the rest is commented out for debugging purposes) I get a Debug Assertion Failed! error. And inside my function call stack I can see it is dying in dbgheap.c at Line 1963 in _CrtIsValidHeapPointer. Does this mean anything to anyone and if so, can you please help me figure out how to get around this bug. Thanks!



Re: Visual C++ General VS 2005 and Qt QString

Peter Ritchie

If that's the only function call the toStdString is corrupting the heap. Can you reproduce the problem with something like:

QString selected;

std:Tongue Tiedtring sname = selected.toStdString();

What happens when you try:

char * p = selected.toStdString().c_str();






Re: Visual C++ General VS 2005 and Qt QString

TDobmeye

Yes the problem can be reproduced like you say in the first example. The selected QString gets passed into my function and I am able to print it out using a qDebug( ) statement. Also if I try to create a char* how you say I get the same problem. That is what I was initially trying to do but I was getting the same error so I was trying to break it into individual steps to see where my problem was. Thanks again!



Re: Visual C++ General VS 2005 and Qt QString

TDobmeye

It seems Visual Studio has problems with the std:Tongue Tiedtring class. If I avoid using the std:Tongue Tiedtring variable, I get no crashes. Unfortunately, some functions in a library I have to use require a std:Tongue Tiedtring to be passed in so I need to use std:Tongue Tiedtrings. Any ideas why VS 2005 seems to have an issue using std:Tongue Tiedtring



Re: Visual C++ General VS 2005 and Qt QString

Peter Ritchie

Could be that you're linking to a library that wasn't built for the same version of Visual Studio that you're using...

another way getting a std:: string:

Code Snippet

std::string((const char*)qstr);






Re: Visual C++ General VS 2005 and Qt QString

TDobmeye

Peter Ritchie wrote:

Could be that you're linking to a library that wasn't built for the same version of Visual Studio that you're using...

another way getting a std:: string:

Code Snippet

std::string((const char*)qstr);

How do I link to the correct library then Are you saying to just cast the QString to a char* Thanks!





Re: Visual C++ General VS 2005 and Qt QString

TDobmeye

TDobmeye wrote:
Are you saying to just cast the QString to a char*

The compiler will not let me cast a QString to a char* or const char*.





Re: Visual C++ General VS 2005 and Qt QString

TDobmeye

I have done more debugging and it appears to only occur when I pass a QString from the SIGNAL to the SLOT. I have called the SLOT with locally declared QStrings and the code works properly. But whenever I try to use the SIGNAL to pass the QString into the SLOT it crashes. So it seems that it must be a Qt thing with VS 2005. I never had this problem with Qt and VS 2003. Thanks for any additional inputs you may have.



Re: Visual C++ General VS 2005 and Qt QString

Peter Ritchie

There used to be a cast operator. They must have removed it in 4.3. You could try:

Code Snippet

std::string(qstr.ascii());






Re: Visual C++ General VS 2005 and Qt QString

Peter Ritchie

This is starting to get very QT specific. I suggest that http://lists.trolltech.com/qt-interest/ may be a better place to look for help on this topic.




Re: Visual C++ General VS 2005 and Qt QString

Peter Ritchie

TDobmeye wrote:
I have done more debugging and it appears to only occur when I pass a QString from the SIGNAL to the SLOT. I have called the SLOT with locally declared QStrings and the code works properly. But whenever I try to use the SIGNAL to pass the QString into the SLOT it crashes. So it seems that it must be a Qt thing with VS 2005. I never had this problem with Qt and VS 2003. Thanks for any additional inputs you may have.
That brings up an important issue, are you using the same lib you used with 2003 with 2005 That's not supported.




Re: Visual C++ General VS 2005 and Qt QString

TDobmeye

Peter Ritchie wrote:
That brings up an important issue, are you using the same lib you used with 2003 with 2005 That's not supported.
When you say the same lib, do you mean the same Qt lib If so yes, I have used Qt 4.3.0 with 2003 and it worked. If you don't mean the Qt libs which libs do you mean




Re: Visual C++ General VS 2005 and Qt QString

TDobmeye

Peter Ritchie wrote:

There used to be a cast operator. They must have removed it in 4.3. You could try:

Code Snippet

std::string(qstr.ascii());

They also removed qstr.ascii( ) from Qt 3 to Qt 4. The way to do it now is the qstr.toStdString( ).c_str( ). I used the .ascii( ) function all the time in Qt 3 and wished they still had it.





Re: Visual C++ General VS 2005 and Qt QString

TDobmeye

Peter Ritchie wrote:
This is starting to get very QT specific.

The reason I thought this might be more VS based is because it worked fine in VS 2003 before but not now in VS 2005. But it now does seem to be leaning a little more towards possibly being Qt itself based on all the tests I have tried for it.





Re: Visual C++ General VS 2005 and Qt QString

TDobmeye

I got it working by doing a

Code Snippet

char* str = strdup( qstr.toAscii( ).data( ) );

I am still having similar problems though. I have a function that I call that returns a std:Tongue Tiedtring, and when I try to do a .c_str( ) call on this std:Tongue Tiedtring, it dies on me. Has VS 2005 changed the way they handle strings