August 23, 2011

jr_jags jr_jags
Lab Rat
87 posts

How to Capture an Image in a QML

 

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?

7 replies

August 23, 2011

mlong mlong
Mad Scientist
1517 posts

The source code for the qmlviewer app uses the line

  1.     QPixmap::grabWidget(canvas).save(snapFileName);

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

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

August 24, 2011

jr_jags jr_jags
Lab Rat
87 posts

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

August 24, 2011

timoph timoph
Lab Rat
17 posts

jr_jags wrote:
where will be the destination of the saved image that i capture?
To the application’s working path so I’d add a path to the file. something like QDir::homePath() + “/fileName”

September 4, 2011

jr_jags jr_jags
Lab Rat
87 posts

can i use this in QML?

September 5, 2011

mlong mlong
Mad Scientist
1517 posts

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.

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

September 5, 2011

jr_jags jr_jags
Lab Rat
87 posts

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

September 5, 2011

sriks sriks
Lab Rat
122 posts

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

 
  ‹‹ music: how to list      [Solved] Is it possible to have two mouse areas process the same mouse event? ››

You must log in to post a reply. Not a member yet? Register here!