Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Qt convert cFilename to type QString for creating a Qsound object

    General and Desktop
    3
    3
    625
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ?
      A Former User last edited by A Former User

      Hello,
      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
      Thank you

      ? 1 Reply Last reply Reply Quote 0
      • ?
        A Former User @Guest last edited by

        @VInay123 Hi! The answer PiotrNycz gave you on stackoverflow looks promising.

        1 Reply Last reply Reply Quote 1
        • Chris Kawa
          Chris Kawa Moderators last edited by Chris Kawa

          Hi,

          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 cFilename is 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 cFilename is of type TCHARthat can map to different underlying types depending on that define.

          If UNICODE is defined, then the cFileName is of type wchar_t[] and (on Windows) it's a UTF-16 string. To convert that to QString you'd use:

          QString foo = QString::fromWCharArray(your_file_descriptor.cFileName);
          

          If UNICODE is not defined then the cFilename member is of type char[] and it's an ANSI string. For that you can use:

          QString foo = QString::fromLatin1(your_file_descriptor.cFileName);
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post