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. Issue printing in QtQuick app

Issue printing in QtQuick app

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 2 Posters 970 Views
  • 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.
  • C Offline
    C Offline
    Cyrille de Brebisson
    wrote on last edited by
    #1

    Hello,

    I am trying to print in a QtQuick app.
    in my main.cpp, I have changed the QGuiApplication into a QApplication and I have added printsupport in my .pro file.

    I have a button in qml that calls:

    void CBSModel::print()
    {
        qDebug() << 1;
        QPrinter printer(QPrinter::HighResolution);
        QPrintDialog dialog(&printer, nullptr);
        dialog.setWindowTitle(tr("Print couder mask"));
        if (dialog.exec() != QDialog::Accepted) return;
    }
    

    But calling this function causes a crash once the function returns...
    Is there anything that I am missing that is causing such a crash?
    I have no problem calling other pieces of code from QML.
    removing the call to dialog.exec() makes the crash go away.

    Cyrille

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What version of Qt are you using ?
      On what OS ?
      Can you post the stack trace ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Cyrille de Brebisson
        wrote on last edited by
        #3

        Hello,

        QT 5.11.2
        I get a "SIGSEV"

        Here is the raw data...

        onecoreuap\shell\windows.storage\viewsettings.cpp(3603)\windows.storage.dll!76081EBE: (caller: 76081F4F) ReturnHr(1) tid(180) 80004005 Unspecified error

        1 QQuickPointerMouseEvent::isDoubleClickEvent qquickevents.cpp 1514 0x217ecd8b
        2 QQuickWindowPrivate::deliverMatchingPointsToItem qquickwindow.cpp 2540 0x2181ff02
        3 QQuickWindowPrivate::deliverPressOrReleaseEvent qquickwindow.cpp 2524 0x2182121b
        4 QQuickWindowPrivate::deliverMouseEvent qquickwindow.cpp 1761 0x21821556
        5 QQuickWindowPrivate::deliverPointerEvent qquickwindow.cpp 2317 0x21821f9f
        6 QQuickWindowPrivate::handleMouseEvent qquickwindow.cpp 2152 0x21822bba
        7 QQuickWindow::mousePressEvent qquickwindow.cpp 2119 0x21822fe4
        8 QWindow::event qwindow.cpp 2242 0xcb54880
        9 QQuickWindow::event qquickwindow.cpp 1634 0x218247ab
        10 QApplicationPrivate::notify_helper qapplication.cpp 3727 0x2c5e85ca
        11 QApplication::notify qapplication.cpp 3099 0x2c5efb83
        12 QCoreApplication::notifyInternal2 qcoreapplication.cpp 1048 0x1a514e01
        13 QCoreApplication::sendSpontaneousEvent qcoreapplication.h 237 0xcb4acae
        14 QGuiApplicationPrivate::processMouseEvent qguiapplication.cpp 2081 0xcb4acae
        15 QGuiApplicationPrivate::processWindowSystemEvent qguiapplication.cpp 1816 0xcb4c589
        16 QWindowSystemInterface::sendWindowSystemEvents qwindowsysteminterface.cpp 1032 0xcb2df99
        17 QWindowsGuiEventDispatcher::sendPostedEvents qwindowsguieventdispatcher.cpp 82 0x3e2adcb4
        18 qt_internal_proc(HWND__ *, unsigned int, unsigned int, long) *16 qeventdispatcher_win.cpp 237 0x1a5650d1
        19 USER32!AddClipboardFormatListener 0x7546be6b
        20 USER32!DispatchMessageW 0x7546833a
        21 USER32!DispatchMessageW 0x75467bee
        22 USER32!DispatchMessageW 0x754679d0
        23 QEventDispatcherWin32::processEvents qeventdispatcher_win.cpp 629 0x1a56482c
        24 QWindowsGuiEventDispatcher::processEvents qwindowsguieventdispatcher.cpp 74 0x3e2adc87
        25 QEventLoop::processEvents qeventloop.cpp 136 0x1a5134b0
        26 QEventLoop::exec qeventloop.cpp 214 0x1a513908
        27 QCoreApplication::exec qcoreapplication.cpp 1336 0x1a51bff6
        28 QGuiApplication::exec qguiapplication.cpp 1761 0xcb415c6
        29 QApplication::exec qapplication.cpp 2901 0x2c5e84a9
        30 qMain main.cpp 40 0x4018d4
        31 WinMain *16 qtmain_win.cpp 104 0x40ce65
        32 main 0x431a3d

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Can you provide a minimal compilable example that triggers this ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          C 1 Reply Last reply
          0
          • SGaistS SGaist

            Can you provide a minimal compilable example that triggers this ?

            C Offline
            C Offline
            Cyrille de Brebisson
            wrote on last edited by
            #5

            Hello,

            After a lot of work, I found the following:

            if you use the first version of the "print" code, things work
            if you use the 2nd version (with the listView), it crashes!!!!
            To reproduce the bug, compile/start the app. Press on the "print" button, click on cancel on the print dialog box, wait 1~2 seconds... it crashes...

            main.qml // This version works...

            import QtQuick 2.9
            import QtQuick.Controls 2.4
            import "qrc:/qml/" //import the qml folder
            import CBSModel 1.0
            
            ApplicationWindow { visible: true; width: 600; height: 600;
            //        SwipeView { anchors.fill: parent;
                            Button   { text: qsTr("Print"); onPressed: CBSModel.printCouder() }
            //        }
            }
            

            main.qml // This version crashes!

            import QtQuick 2.9
            import QtQuick.Controls 2.4
            import "qrc:/qml/" //import the qml folder
            import CBSModel 1.0
            
            ApplicationWindow { visible: true; width: 600; height: 600;
                    SwipeView { anchors.fill: parent;
                            Button   { text: qsTr("Print"); onPressed: CBSModel.printCouder() }
                    }
            }
            

            main.cpp

            #include <QApplication>
            #include <QQmlApplicationEngine>
            #include <QQuickStyle>
            #include <QIcon>
            #include "model.h"
            
            CBSModel *CBSModel::singleton= nullptr;
            
            int main(int argc, char *argv[])
            {
                QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
                QIcon iconApplication;
            #ifdef WINDOWS
                iconApplication = readIcoFile("qrc:/Resources/cbscope.ico");
            #else
                iconApplication.addFile("qrc:/Resources/cbscope.icns");
            #endif
                qmlRegisterSingletonType<CBSModel>("CBSModel", 1, 0, "CBSModel", CBSModel::SingletonProvider);
                QApplication app(argc, argv);
                QQmlApplicationEngine engine;
                engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
                if (engine.rootObjects().isEmpty())
                    return -1;
                    int ret= app.exec();
                return ret;
            }
            

            model.h

            #ifndef CBSMODEL_H
            #define CBSMODEL_H
            #include <QObject>
            #include <QQmlEngine>
            #include <QPrinter>
            #include <QPainter>
            #include <QPrintDialog>
            
            class CBSModel : public QObject {
                Q_OBJECT
            public:
                CBSModel(QObject *parent=nullptr): QObject(parent) { }
                  static CBSModel *singleton;
                static QObject *SingletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
                {   (void)engine; (void)scriptEngine;
                    if (singleton==nullptr) singleton= new CBSModel();    return singleton;
                }
                Q_INVOKABLE void printCouder()
                {
                    QPrinter printer(QPrinter::HighResolution);
                    QPrintDialog dialog(&printer, nullptr);
                    dialog.setWindowTitle(tr("Print couder mask"));
                    if (dialog.exec() != QDialog::Accepted) return;
                    printer.setOutputFileName("couder.ps");
                    QRect area(printer.pageRect());
                    int dpi= printer.resolution();
                    QPoint c= area.center();
                    QPainter painter;
                    painter.begin(&printer);
                    painter.end();
                }
            };
            
            #endif
            

            Cyrille

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Cyrille de Brebisson
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • C Offline
                C Offline
                Cyrille de Brebisson
                wrote on last edited by
                #7

                hello

                Is there any way to turn on in QtCreator buffer overruns detection similar to the ones build in Visual Studio?

                Cyrille

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  I am not aware of such a feature (it doesn't mean that it doesn't exists though), but you can also use VS to build your application and use the tools you need.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  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