I tried the code shown here: How to take ScreenShot Qt/QML
On execution I am getting the error written in the title.
My main.cpp is:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickWindow>
#include <QImage>
#include <QDebug>
#include "screenshot.h"
#include <QQuickView>
#include <QQmlContext>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
const char* drigUi = "DrigUI";
qmlRegisterType <screenCapture> (drigUi, 1, 0, "ScreenShot");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
I used this capture function:
void screenCapture::capture(QString const &path) const
{
QImage img = currentView_->grabWindow();
img.save(path);
}
and added the following in the constructor:
currentView_ = new QQuickView;
My main.qml :
import QtQuick 2.4
import QtQuick.Window 2.2
import DrigUI 1.0
Window
{
visible: true
height: 370
width: 370
ScreenShot { id: screenShot }
Rectangle
{
id: ll
height: 30
width: 50
x: 180; y: 0; color: "red"
MouseArea
{
anchors.fill: parent
onClicked: screenShot.capture ("l.png")
}
}
}
What does that error mean? What is the way to solve it? What else info can I provide here?