Hi,
Often, but not each time, "toStdString" is converting the string into an empty string !! It is completely random and do not know how to solve this problem ?
do you have any idea ?
Thanks
Hi,
Often, but not each time, "toStdString" is converting the string into an empty string !! It is completely random and do not know how to solve this problem ?
do you have any idea ?
Thanks
Did you make sure the input string is not empty in the first place? if so how?
Post your 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.
Yes, I'm in the debugger and the debugger show me the content of my string... everything sounds fine !!!
Here is the code... so simple !!!
string file = _currentFilePath.toStdString();
can you show the following several lines too?
==========================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.
Thanks,
I have this problem since several months !
Here is the complete method :
Qt Code:
void psMainWindow::on_Menu_Save() { if (_currentFilePath.length() < 1) { on_Menu_SaveAs(); return; } UpdatePanelWidget::Start(); pureGraph::IE::Exporter exporter; string file = _currentFilePath.toStdString(); exporter.Export(GlobalContext::Scene, file); UpdatePanelWidget::Stop(); }To copy to clipboard, switch view to plain text mode
and you say that when you stand on line 13 in the debugger, '_currentFilePath' has a valid string in it, and 'file' is an empty string?
==========================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.
I work with Visual Studio 2008 (for info) and I've also seen this post but not sure it is related : http://www.qtcentre.org/threads/3875...tring-heap-bug
Yes, on line 13... '_currentFilePath' is valid but 'file' is empty !
Try to clean and rebuild the project/solution.
==========================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.
Thanks,
I have try on several machines... I have this bug since several month now !!!! I have no idea on how I can fix this !
Is there another way to convert a QString to a std::string ?
I have try : qPrintable(_currentFilePath)
But still have the same error !!!
Are you sure your QString doesn't contain Unicode characters not handled??std::string QString::toStdString () const
...
If the QString contains Unicode characters that the QTextCodec::codecForCStrings() codec cannot handle, using this operator can lead to loss of information.
...
A camel can go 14 days without drink,
I can't!!!
Yes, it is a simple file name !!!
This isn't a warranty that you don't have any "strange character".
What is the language of your system?
Can you try with QString::toStdWString??
A camel can go 14 days without drink,
I can't!!!
Thanks,
I have try with :
std::wstring wFileName = _currentFilePath.toStdWString();
string fileName1 = _currentFilePath.toStdString(); // BUG
string fileName2 = qPrintable(_currentFilePath);
But all theses one are empty !! But not _currentFilePath ??
I had the same problem. It does not seem to be a bug in Qt, but one in the VC Compiler.
If you write toStdString().c_str() in one line, the result is empty.
If you write it in two lines, the result is correct:
Qt Code:
std::string txt_str = txt.toStdString(); const char* txt_str_chr = txt_str.c_str(); // works, content is "Some text" const char* txt_str_chr_one_line = txt.toStdString().c_str(); // empty!! vc-bug??To copy to clipboard, switch view to plain text mode
I tried this in VS 2013
Bookmarks