I have a path stored in cFilename object, and Iam trying to create a QSound Object, but while constructing the object I have give the path name as argument or during using play function i have to give the path name, and QSound takes only of type QString. How do I convert the cFilename object to of type QString? And this path has a pointer which points to a share directory of the folder.
If there is an any alternate solution please let me know
Thank you
Asked
Active
Viewed 192 times
2

Vinay Balaji Rajputh
- 17
- 3
-
What is type of your cFilename object? Can you get a 'plain' string from it ?(i.e. does it have something like c_str() method?) – mvidelgauz Jun 18 '16 at 09:41
-
As a step towards QString - use conversion to std::string: http://stackoverflow.com/questions/16195321/cannot-convert-findfiledata-cfilename-to-string – PiotrNycz Jun 18 '16 at 09:42
-
how do i convert cstring to qstring? – Vinay Balaji Rajputh Jun 18 '16 at 09:47
-
1MFC CString? QString has a bunch of static fromXXX functions, just open QString header file and look which one appropriate. Be careful, CString itself depends on the compiling environment also. – douyw Jun 18 '16 at 12:03
2 Answers
1
You need two steps:
1. CString
to std::string
:
CString cString("Hello");
CT2CA convertedString(cstring);
std::string stdString(convertedString);
2. std::string
to QString
:
QString qtString = QString::fromStdString(stdString);

OneStackOverflowUser
- 153
- 9
0
You don't mention the type of cFilename
, but if is std::string
you could do QString::fromUtf8(cFilename.c_str())
. If it is a const char*
then you could do QString::fromUtf8(cFilename)
.

Jesper Juhl
- 30,449
- 3
- 47
- 70
-
what if it is a CString? how to convert cString to QString? – Vinay Balaji Rajputh Jun 18 '16 at 11:13