Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qt convert cFilename to type QString for creating a Qsound object
A Former User last edited by A Former User
I have a path stored in cFilename object, and iam trying to create a QSound Object, but while consructing 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
A Former User last edited by
When talking about non Qt types it's crucial to say what type they are, not just their name, otherwise it's like asking "how can I convert foo to QObject" without saying what foo is.
Anyway, because the name is often used in Win32 family of APIs, I'm guessing that
cFilenameis a member of a file information record, for example this one. Is that a correct guess?
If so, then there are two possible answers to this question, and they depend on whether or not you have defined UNICODE in your app (most probably yes, even if not knowingly, because that's the default these days). That's because
cFilenameis of type
TCHARthat can map to different underlying types depending on that define.
If UNICODE is defined, then the
cFileNameis of type
wchar_tand (on Windows) it's a UTF-16 string. To convert that to
QString foo = QString::fromWCharArray(your_file_descriptor.cFileName);
If UNICODE is not defined then the
cFilenamemember is of type
charand it's an ANSI string. For that you can use:
QString foo = QString::fromLatin1(your_file_descriptor.cFileName);