The problem you see has nothing to do with the code you posted as such.
It probably has to do with shared resources or/and not protected shared resources in your code.
But its hard to say with out seeing more of the relevant code.
The problem you see has nothing to do with the code you posted as such.
It probably has to do with shared resources or/and not protected shared resources in your code.
But its hard to say with out seeing more of the relevant code.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Ok sorry..
If you want see the same problem you can:
- create a new qt application in visual Studio 2005. In the main file add this code:
Qt Code:
#include <QString> ... ... std::string converted = test.toStdString();To copy to clipboard, switch view to plain text mode
Now, open the project settings, go to C/C++ and then Code generation.
Here the field Runtime Library is setting to "Multi-threaded Debug DLL (/MDd)". You change this setting at "Multi-threaded DLL (/MD)".
Now set a break point in your main function, run and step by step observe the value of the variable "converted": the function toStdString() does'nt work.
The problem is that my application must be configured as Multi-threaded DLL (/MD).
Thanks, Bye!!
when you set option to Multi-threaded DLL (/MD), you dont have debug information in your exe file. are you sure that there is a null pointer?
sory for me poor english
Try printing out to std output the following:
Qt Code:
std::string converted = test.toStdString(); qDebug()<<test2;To copy to clipboard, switch view to plain text mode
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
zoz (30th May 2010)
Not null pointer, i have an unhandled exception. I have a null pointer if the subsystem is setting to Console application.
By the way, I ran the example you gave, that is, application with Multi-threaded DLL (/MD) option, and it ran fine, the ste::string got filled correctly from the QString, and back again to QString.
Your problem is somewhere else.
EDIT: wait a minute, do you have Qt release mode? maybe you only have a debug mode Qt.. although it should complain at link time then...
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Try printing out to std output the following:
[CODE
QString test = "Test";
std::string converted = test.toStdString();
QString test2 = QString::fromStdString(converted);
qDebug()<<test2;
][/CODE]
The output is: "Test"
Which proves the conversion works fine.The output is: "Test"
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
zoz (30th May 2010)
Ok Thanks... i try to work.
Sorry, but if i printing:
qDebug() << test.toStdString().c_str();
my output is wrong: thera are bad character after the word Test.
Is correct?
Hi,
This character is the NULL character that means that the string finish there. Search on the web about strings on C or C++ and you will see that need to be terminated with "\0" that is the NULL character
Òscar Llarch i Galán
The null character should not be printed out.
It could be that qDebug() doesn't stop at the null char when it gets a c style pointer, but I would be surprised if that is the case.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Oh sorry, the bad character are Before "Test".. for example: "}→qwTEST"
Could you provide a minimal compilable example reproducing the problem?
Bookmarks