[Qt-interest] QString::toStdString() problem

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Mon Mar 8 10:44:19 CET 2010


hakiim the dream wrote on Monday, March 08, 2010 9:44 AM:
> ...
> I get a QString from OpenFileDialog and apply a method named
> splitAndMerge on it, to convert it from "C:/blabla/.." to
> "C:\\blabla\\.." .

You could also call http://doc.trolltech.com/4.6/qdir.html#toNativeSeparators which does this for you already.
  
> I apply that function inside the private open() slot.
> Then i convert that QString to std::string, which is a public pointer
> member of the same class. (string * srcFilename) I just try to
> allocate the string with srcFilename = new string(s.toStdString());
> or srcFilename = new string(s.toLatin1()); inside the same slot, just
> after applying the splitAndMerge method, but neither of them works.  

How does it not work? What is the resulting srcFilename? Empty '\0'? "Garbage" (random characters)? Does your "splitAndMerge" method actually work?

Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list