Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to Capture an Image in a QML
Forum Updated to NodeBB v4.3 + New Features

How to Capture an Image in a QML

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 4 Posters 6.0k 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.
  • J Offline
    J Offline
    jr_jags
    wrote on last edited by
    #1

    I would like to save an image when my QML application is running, just like a camera inside the application,
    How can i do that?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      The source code for the qmlviewer app uses the line
      @
      QPixmap::grabWidget(canvas).save(snapFileName);
      @

      where canvas is the QDeclarativeView* and snapFileName is the filename to save.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jr_jags
        wrote on last edited by
        #3

        where will be the destination of the saved image that i capture?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          timoph
          wrote on last edited by
          #4

          [quote author="jr_jags" date="1314181801"]where will be the destination of the saved image that i capture?[/quote]
          To the application's working path so I'd add a path to the file. something like QDir::homePath() + "/fileName"

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jr_jags
            wrote on last edited by
            #5

            can i use this in QML?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #6

              You'll need to write some C++ code to handle this. However, with a slot or a Q_INVOKABLE method, you can trigger the functionality from your QML code.

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jr_jags
                wrote on last edited by
                #7

                so ill use the .cpp file to use screenshot on my qml

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  srikanth_trulyit
                  wrote on last edited by
                  #8

                  yes, put the @mlong inside a slot. Optionally you can pass the path to which you want to save as a parameter.

                  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