Qt Forum

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

    How to Capture an Image in a QML

    QML and Qt Quick
    4
    8
    5335
    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.
    • J
      jr_jags last edited by

      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 Reply Quote 0
      • M
        mlong last edited by

        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 Reply Quote 0
        • J
          jr_jags last edited by

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

          1 Reply Last reply Reply Quote 0
          • T
            timoph last edited by

            [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 Reply Quote 0
            • J
              jr_jags last edited by

              can i use this in QML?

              1 Reply Last reply Reply Quote 0
              • M
                mlong last edited by

                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 Reply Quote 0
                • J
                  jr_jags last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • S
                    srikanth_trulyit last edited by

                    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 Reply Quote 0
                    • First post
                      Last post