Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How can I convert a QJSValue List into a QString List?
Qt 6.12 LTS is out! See what's new in the release blog

How can I convert a QJSValue List into a QString List?

Scheduled Pinned Locked Moved QML and Qt Quick
qjsvalueqstringqtmultimedia
4 Posts 3 Posters 4.1k Views 1 Watching
  • 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
    #1

    I'm new to QtQuick, here's my problem.
    I like to put a set of available cameras connected to my computer in a combo box. However, when I use the QtMultimedia.availableCameras, the list is in QJSValue instead of QString.
    Is there any method or functions that I can use to get the list of camera names?

    So far my combo box has shown 2 spaces, blank. So I know it has the value that it has 2 items in the list, but couldn't display the name.
    Thank you for your help, much appreciated.

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xargs1
      wrote on last edited by
      #2

      I couldn't get availableCameras to work as documented (I got an array of strings back), but I think it's supposed to work like this:

      ComboBox {
          model: ListModel { }


      
          Component.onCompleted: {
 
             for (var camera in QtMultimedia.availableCameras)

                  model.append({ "text": camera.displayName })

          }
   
       }
      
      ? 1 Reply Last reply
      0
      • X xargs1

        I couldn't get availableCameras to work as documented (I got an array of strings back), but I think it's supposed to work like this:

        ComboBox {
            model: ListModel { }


        
            Component.onCompleted: {
 
               for (var camera in QtMultimedia.availableCameras)

                    model.append({ "text": camera.displayName })

            }
   
         }
        
        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        @xargs1 said:

        In order to get availableCameras to work, you have to first import QtMultimedia 5.4
        Can we just give ListModel an empty set of bracket?
        This didn't work, it says
        modelData is not defined

        Should I write part of the code in another QML file?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mohsen Mazaheri
          wrote on last edited by
          #4

          Hello, I had the same problem with showing the list of cameras in a ComboBox. the correct code is:

               ComboBox {
                    id: cmbVideoCaptures
                    model: QtMultimedia.availableCameras
                    textRole: "displayName"
                    valueRole: "deviceId"
                }
          
          
          1 Reply Last reply
          1

          • Login

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