Results 1 to 6 of 6

Thread: QQuickWindow::grabWindow: scene graph already in use

  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default QQuickWindow::grabWindow: scene graph already in use

    I tried the code shown here: http://stackoverflow.com/questions/1...eenshot-qt-qml

    On execution I am getting the error written in the title.

    My **main.cpp** is:

    Qt Code:
    1. #include <QGuiApplication>
    2. #include <QQmlApplicationEngine>
    3. #include <QQuickWindow>
    4. #include <QImage>
    5. #include <QDebug>
    6. #include "screenshot.h"
    7. #include <QQuickView>
    8. #include <QQmlContext>
    9.  
    10. int main(int argc, char *argv[])
    11. {
    12. QGuiApplication app(argc, argv);
    13.  
    14. const char* drigUi = "DrigUI";
    15. qmlRegisterType <screenCapture> (drigUi, 1, 0, "ScreenShot");
    16.  
    17. QQmlApplicationEngine engine;
    18. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    19.  
    20. return app.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 
    I used this **capture** function:

    Qt Code:
    1. void screenCapture::capture(QString const &path) const
    2. {
    3. QImage img = currentView_->grabWindow();
    4. img.save(path);
    5. }
    To copy to clipboard, switch view to plain text mode 
    and added the following in the constructor:

    Qt Code:
    1. currentView_ = new QQuickView;
    To copy to clipboard, switch view to plain text mode 

    My ***main.qml*** :

    Qt Code:
    1. import QtQuick 2.4
    2. import QtQuick.Window 2.2
    3.  
    4. import DrigUI 1.0
    5.  
    6. Window
    7. {
    8. visible: true
    9. height: 370
    10. width: 370
    11.  
    12. ScreenShot { id: screenShot }
    13.  
    14. Rectangle
    15. {
    16. id: ll
    17. height: 30
    18. width: 50
    19. x: 180; y: 0; color: "red"
    20. MouseArea
    21. {
    22. anchors.fill: parent
    23. onClicked: screenShot.capture ("l.png")
    24. }
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

    What does that error mean? What is the way to solve it? What else info can I provide here?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QQuickWindow::grabWindow: scene graph already in use

    My I ask why you want to create a screenshot of an empty QQuickView?
    Wouldn't you want to take the screenshot of the Window you create in QML?

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    TheIndependentAquarius (17th October 2015)

  4. #3
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: QQuickWindow::grabWindow: scene graph already in use

    Thanks for tolerating my ignorance. I got your point.

    I'd be grateful if you could explain the meaning of the error in title.

    I realized that I wasn't using the `QQuickView` anywhere in `main.cpp`. so that meant that `QQuickView`, I was using, was empty.

    My other part of program is using `QQuickWindow` instead of `QQuickView`, so I replaced `QQuickView` with `QQuickWindow` as follows:

    ScreenCapture.h
    Qt Code:
    1. #ifndef SCREENSHOT_H
    2. #define SCREENSHOT_H
    3.  
    4. #include <QObject>
    5.  
    6. class QString;
    7. class QQuickWindow;
    8.  
    9. class screenCapture : public QObject
    10. {
    11. Q_OBJECT
    12. public:
    13. explicit screenCapture (QQuickWindow *parent = 0);
    14.  
    15. public slots:
    16. void capture (QString const &path) const;
    17.  
    18. private:
    19. QQuickWindow *currentWindow;
    20. };
    21.  
    22. #endif // SCREENSHOT_H
    To copy to clipboard, switch view to plain text mode 

    ScreenCapture.cpp
    Qt Code:
    1. #include <QPixmap>
    2. #include <QQuickView>
    3. #include <QDebug>
    4. #include "screenshot.h"
    5.  
    6. screenCapture::screenCapture(QQuickWindow *currentWindow) :
    7. QObject(0), currentWindow (currentWindow)
    8. {
    9. }
    10.  
    11. void screenCapture::capture (QString const &path) const
    12. {
    13. QImage p = currentWindow->grabWindow ();
    14. bool kk = p.save (path);
    15. qDebug () << kk;
    16. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QGuiApplication app(argc, argv);
    4.  
    5. QQmlApplicationEngine engine;
    6. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    7.  
    8. QObject *topLevel = engine.rootObjects().value(0);
    9. QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
    10.  
    11. screenCapture launcher (window);
    12.  
    13. engine.rootContext()->setContextProperty("ScreenShot", &launcher);
    14.  
    15. window->show();
    16.  
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    Now, in QML side, we can directly use

    `ScreenShot.capture ("/home/*****/Desktop/l.png")`

    anywhere we want. It works.
    Last edited by TheIndependentAquarius; 17th October 2015 at 09:40.

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QQuickWindow::grabWindow: scene graph already in use

    Do you still get the error?

    Cheers,
    _

  6. #5
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: QQuickWindow::grabWindow: scene graph already in use

    No, it seems I wasn't clear enough.

    In the above I have shown how the problem got solved.

    Also, I requested you tell me the meaning of the error message.

  7. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QQuickWindow::grabWindow: scene graph already in use

    I have no idea, the error might even be misleading, intended for a different code path that would lead to the check.

    Cheers,
    _

Similar Threads

  1. How to create own graph(Curve graph) using Qt ?
    By karankumar1609 in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2013, 12:48
  2. Replies: 1
    Last Post: 10th April 2013, 10:08
  3. Ugly QQuickWindow
    By Brandybuck in forum Qt Quick
    Replies: 0
    Last Post: 5th February 2013, 02:05
  4. Open Scene Graph widget?
    By Caius Aérobus in forum Qt Programming
    Replies: 2
    Last Post: 19th November 2007, 14:23
  5. Qt4 scene graph model
    By grabner in forum Qt Programming
    Replies: 1
    Last Post: 10th May 2006, 09:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.