Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPrintPreviewDialog crashes on selecting print button.
Forum Updated to NodeBB v4.3 + New Features

QPrintPreviewDialog crashes on selecting print button.

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 3 Posters 3.4k Views 2 Watching
  • 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.
  • K Offline
    K Offline
    kenchan
    wrote on last edited by
    #6

    @Sheetal OK, thanks for posting that. Did you debug and find where it crashes yet?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sheetal
      wrote on last edited by
      #7

      @Kenchan Will post the debugging result once I am able to reproduce. It is Sporadic. It happens only once in a while. In last 10 days it happened only 2-3 times. That is the problem.

      call stack when last time it crashed. This may not help as it is not full call stack. But still.

      Thu Nov 30 18:59:44 2017 Logger.cpp logStackTrace : 670 Stack Trace: Segmentation Fault
      /usr/local/qt/lib/libQt5PrintSupport.so.5(+0x38a62) [0x7fa8d35b1a62]
      /usr/local/qt/lib/libQt5PrintSupport.so.5(+0x4f563) [0x7fa8d35c8563]
      /usr/local/qt/lib/libQt5Core.so.5(_ZN11QMetaObject8activateEP7QObjectiiPPv+0x2c1) [0x7fa8d23bf521]
      /usr/local/qt/lib/libQt5Widgets.so.5(_ZN9QLineEdit13focusOutEventEP11QFocusEvent+0x89) [0x7fa8d31b8189]
      /usr/local/qt/lib/libQt5Widgets.so.5(_ZN7QWidget5eventEP6QEvent+0x57c) [0x7fa8d30c7cfc]
      /usr/local/qt/lib/libQt5Widgets.so.5(_ZN9QLineEdit5eventEP6QEvent+0x65) [0x7fa8d31b7ba5]
      /usr/local/qt/lib/libQt5Widgets.so.5(_ZN7QWidget5eventEP6QEvent+0x57c) [0x7fa8d30c7cfc]
      /usr/local/qt/lib/libQt5Widgets.so.5(_ZN9QComboBox5eventEP6QEvent+0x76) [0x7fa8d31783b6]
      /usr/local/qt/lib/libQt5Widgets.so.5(_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent+0x9c) [0x7fa8d308632c]
      /usr/local/qt/lib/libQt5Widgets.so.5(_ZN12QApplication6notifyEP7QObjectP6QEvent+0x3fa) [0x7fa8d308a98a]

      K 1 Reply Last reply
      0
      • K Offline
        K Offline
        kenchan
        wrote on last edited by kenchan
        #8

        @Sheetal OK, i can't see anything in the code that will directly cause a crash. I would be concerned about keeping the m_printer in sync with what the preview dialog settings. Since you are not using the pointer that gets passed into the print function from the print preview dialog your member function will not get updated with those setting. As you are forcing it to print to a pdf file maybe this is not so important.

        I have been using the QPrintPreviewWidget in my own dialog since before 5.6.0 an have not seen intermittent crashes. I only ever had problems with the printer object not being valid in some way but I make sure that does not happen any more.

        I only use the printer pointer passed into the print function and sync my current printer and it's settings from the one currently managed by the widget, which may or may not be the one I passed to it in the first place.

        S 1 Reply Last reply
        0
        • S Sheetal

          @Kenchan Will post the debugging result once I am able to reproduce. It is Sporadic. It happens only once in a while. In last 10 days it happened only 2-3 times. That is the problem.

          call stack when last time it crashed. This may not help as it is not full call stack. But still.

          Thu Nov 30 18:59:44 2017 Logger.cpp logStackTrace : 670 Stack Trace: Segmentation Fault
          /usr/local/qt/lib/libQt5PrintSupport.so.5(+0x38a62) [0x7fa8d35b1a62]
          /usr/local/qt/lib/libQt5PrintSupport.so.5(+0x4f563) [0x7fa8d35c8563]
          /usr/local/qt/lib/libQt5Core.so.5(_ZN11QMetaObject8activateEP7QObjectiiPPv+0x2c1) [0x7fa8d23bf521]
          /usr/local/qt/lib/libQt5Widgets.so.5(_ZN9QLineEdit13focusOutEventEP11QFocusEvent+0x89) [0x7fa8d31b8189]
          /usr/local/qt/lib/libQt5Widgets.so.5(_ZN7QWidget5eventEP6QEvent+0x57c) [0x7fa8d30c7cfc]
          /usr/local/qt/lib/libQt5Widgets.so.5(_ZN9QLineEdit5eventEP6QEvent+0x65) [0x7fa8d31b7ba5]
          /usr/local/qt/lib/libQt5Widgets.so.5(_ZN7QWidget5eventEP6QEvent+0x57c) [0x7fa8d30c7cfc]
          /usr/local/qt/lib/libQt5Widgets.so.5(_ZN9QComboBox5eventEP6QEvent+0x76) [0x7fa8d31783b6]
          /usr/local/qt/lib/libQt5Widgets.so.5(_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent+0x9c) [0x7fa8d308632c]
          /usr/local/qt/lib/libQt5Widgets.so.5(_ZN12QApplication6notifyEP7QObjectP6QEvent+0x3fa) [0x7fa8d308a98a]

          K Offline
          K Offline
          kenchan
          wrote on last edited by kenchan
          #9

          @Sheetal you are right, not very useful...
          BTW, I only use this on Windows and the macOS so don't know how it behaves on Linux.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sheetal
            wrote on last edited by
            #10

            Thanks for the reply @kenchan . Will definitely try changing the m_printer to the one passed in the print() slot. (In this case "p")
            Will post the results.

            K 1 Reply Last reply
            1
            • S Sheetal

              Thanks for the reply @kenchan . Will definitely try changing the m_printer to the one passed in the print() slot. (In this case "p")
              Will post the results.

              K Offline
              K Offline
              kenchan
              wrote on last edited by
              #11

              @Sheetal Another thing that concerns me is keeping the painter as a class member. Looking at the code you could create it on each call in the print function and pass it as a pointer to the other functions that need it when they are called from the print function. The painter would go out of scope at the end of the print function. I am not used to using a painter in any other way, I believe there are restrictions on how and when a painter can be used.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kenchan
                wrote on last edited by
                #12

                @Sheetal I searched the bug reports here but could not see anything relevant.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Sheetal
                  wrote on last edited by
                  #13

                  @Kenchan . Ok. I got your point regarding painter. Will create a local painter object . Thanks for confirming bug report.

                  1 Reply Last reply
                  0
                  • K kenchan

                    @Sheetal OK, i can't see anything in the code that will directly cause a crash. I would be concerned about keeping the m_printer in sync with what the preview dialog settings. Since you are not using the pointer that gets passed into the print function from the print preview dialog your member function will not get updated with those setting. As you are forcing it to print to a pdf file maybe this is not so important.

                    I have been using the QPrintPreviewWidget in my own dialog since before 5.6.0 an have not seen intermittent crashes. I only ever had problems with the printer object not being valid in some way but I make sure that does not happen any more.

                    I only use the printer pointer passed into the print function and sync my current printer and it's settings from the one currently managed by the widget, which may or may not be the one I passed to it in the first place.

                    S Offline
                    S Offline
                    Sheetal
                    wrote on last edited by
                    #14

                    @kenchan said in QPrintPreviewDialog crashes on selecting print button.:

                    I only use the printer pointer passed into the print function and sync my current printer and it's settings from the one currently managed by the widget, which may or may not be the one I passed to it in the first place.

                    I did not get "sync my current printer and it's settings from the one currently managed by the widget, which may or may not be the one I passed to it in the first place."

                    U mean , I should have a m_printer pointer as class member and pass it to QPrintPreviewDialog(), and then in print(QPainter p) slot I should assign p=m_printer?

                    K 1 Reply Last reply
                    0
                    • S Sheetal

                      @kenchan said in QPrintPreviewDialog crashes on selecting print button.:

                      I only use the printer pointer passed into the print function and sync my current printer and it's settings from the one currently managed by the widget, which may or may not be the one I passed to it in the first place.

                      I did not get "sync my current printer and it's settings from the one currently managed by the widget, which may or may not be the one I passed to it in the first place."

                      U mean , I should have a m_printer pointer as class member and pass it to QPrintPreviewDialog(), and then in print(QPainter p) slot I should assign p=m_printer?

                      K Offline
                      K Offline
                      kenchan
                      wrote on last edited by kenchan
                      #15

                      @Sheetal Well, As it tells you in the docs for the QPrintPreviewDialog, you can let the dialog provide a printer or you provide it with one.
                      You can have a printer member as a pointer or as you have it now, but you must know that the user can change the printer and or it settings using the dialog. This means the type of printer and or its settings may change between when the dialog is created and when the print function is called. You must allow for that by and make sure the printer is what you expect when you do the drawing on it.

                      When I use my dialog I do the following:

                      I get a pointer to the default printer make any settings I want to set then pass it to the dialog in its constructor.
                      I make the connection to the print function.
                      I call exec on the dialog.
                      The print function is called.
                      I use the printer pointer passed in and create a painter with it.
                      I draw on the painter.
                      The dialog shows the user the preview.
                      The user may change the paper size or even the printer etc. The print function can be called again when a change is made.
                      The user clicks the print button.
                      The pages get printed to the printer or pdf file whichever the case maybe.
                      The dialog closes.
                      I delete the printer.

                      I hope this helps.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        Sheetal
                        wrote on last edited by
                        #16

                        I am able to get the complete call stack when it crashed. It is as below.
                        There is no problem with painter & printer objects (I have corrected my code as per our previous discussion ). When I debug all calls are made correctly. Nothing suspicious .
                        But, looks like when QPrintPreviewDialog is getting destroyed by Qt at the end of printing there is a problem. or Maybe some events are getting generated after preview dialog is closed.
                        1 CLogger::handleSignal Logger.cpp 618 0x7fe3529e1f27
                        2 __restore_rt 0x7fe34d06e250
                        3 ?? 0x180a090
                        4 QPrintPreviewWidgetPrivate::setZoomFactor(double) 0x7fe34f87fa65
                        5 QPrintPreviewDialogPrivate::_q_zoomFactorChanged() 0x7fe34f896563
                        6 QMetaObject::activate(QObject *, int, int, void * *) 0x7fe34e68d521
                        7 QLineEdit::focusOutEvent(QFocusEvent *) 0x7fe34f486189
                        8 QWidget::event(QEvent *) 0x7fe34f395cfc
                        9 QLineEdit::event(QEvent *) 0x7fe34f485ba5
                        10 QWidget::event(QEvent *) 0x7fe34f395cfc
                        11 QComboBox::event(QEvent *) 0x7fe34f4463b6
                        12 QApplicationPrivate::notify_helper(QObject *, QEvent *) 0x7fe34f35432c
                        13 QApplication::notify(QObject *, QEvent *) 0x7fe34f35898a
                        14 OdvApplication::notify OdvApplication.cpp 53 0x63d13d
                        15 QCoreApplication::notifyInternal2(QObject *, QEvent *) 0x7fe34e663a75
                        16 QApplicationPrivate::setFocusWidget(QWidget *, Qt::FocusReason) 0x7fe34f3565c3
                        17 QApplication::setActiveWindow(QWidget *) 0x7fe34f356c14
                        18 QApplicationPrivate::notifyActiveWindowChange(QWindow *) 0x7fe34f356cc3
                        19 QGuiApplicationPrivate::processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *) 0x7fe34e9b4635
                        20 QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *) 0x7fe34e9b498d
                        21 QWindowSystemInterface::sendWindowSystemEvents(QFlagsQEventLoop::ProcessEventsFlag) 0x7fe34e99696b
                        22 userEventSourceDispatch(_GSource *, int ( *)(void *), void *) 0x7fe34e2d9cb0
                        23 g_main_context_dispatch 0x7fe3470b5d7a
                        24 g_main_context_iterate.isra.24 0x7fe3470b60b8
                        25 g_main_context_iteration 0x7fe3470b616c
                        26 QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) 0x7fe34e6b3a9c
                        27 QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) 0x7fe34e661c1b
                        28 QCoreApplication::exec() 0x7fe34e669956
                        29 main SVGViewMain.cpp 283 0x66a54d

                        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