Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt convert cFilename to type QString for creating a Qsound object

Qt convert cFilename to type QString for creating a Qsound object

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 779 Views
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    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
    0
    • ? 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

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

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

      1 Reply Last reply
      1
      • Chris KawaC Online
        Chris KawaC Online
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by Chris Kawa
        #3

        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
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved