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. Program Crashes giving segmentation fault as an error
Forum Updated to NodeBB v4.3 + New Features

Program Crashes giving segmentation fault as an error

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 386 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.
  • N Offline
    N Offline
    Nirbhik
    wrote on last edited by
    #1

    I am trying to build a Qt App that can interact with SerialPort and plot the result using Qt Chart While trying to run the application, it keeps crashing. When i went into Debug mode i got a segmentation fault error in the following line of code:

    void QWidgetTextControl::setCursorWidth(int width)
    {
        Q_D(QWidgetTextControl);
        if (width == -1)
        ** -->**    width = QApplication::style()->pixelMetric(QStyle::PM_TextCursorWidth, nullptr);
        d->doc->documentLayout()->setProperty("cursorWidth", width);
        d->repaintCursor();
    }
    

    I tried including the QApplication header in the qqwidgettextcontrol.cpp and also added the required modules in CMake file as:

    find_package(Qt6 6.2 REQUIRED COMPONENTS Core Gui Qml Quick Widgets)
    target_link_libraries(be_2App PRIVATE
        Qt6::Core
        Qt6::Gui
        Qt6::Qml
        Qt6::Quick
        Qt6::Widgets
    )
    
    JonBJ 1 Reply Last reply
    0
    • N Nirbhik

      I am trying to build a Qt App that can interact with SerialPort and plot the result using Qt Chart While trying to run the application, it keeps crashing. When i went into Debug mode i got a segmentation fault error in the following line of code:

      void QWidgetTextControl::setCursorWidth(int width)
      {
          Q_D(QWidgetTextControl);
          if (width == -1)
          ** -->**    width = QApplication::style()->pixelMetric(QStyle::PM_TextCursorWidth, nullptr);
          d->doc->documentLayout()->setProperty("cursorWidth", width);
          d->repaintCursor();
      }
      

      I tried including the QApplication header in the qqwidgettextcontrol.cpp and also added the required modules in CMake file as:

      find_package(Qt6 6.2 REQUIRED COMPONENTS Core Gui Qml Quick Widgets)
      target_link_libraries(be_2App PRIVATE
          Qt6::Core
          Qt6::Gui
          Qt6::Qml
          Qt6::Quick
          Qt6::Widgets
      )
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Nirbhik
      Since it's a runtime error your compiling/linking is not relevant.

      If it "crashes" run under debugger and look at the stack trace pane.

      Make sure you have created the QApplication object by the time this code is executed? If it crashes on the line you show make sure QApplication::style() is not nullptr. (If it could be following line, same for d->doc->documentLayout().)

      N 1 Reply Last reply
      0
      • JonBJ JonB

        @Nirbhik
        Since it's a runtime error your compiling/linking is not relevant.

        If it "crashes" run under debugger and look at the stack trace pane.

        Make sure you have created the QApplication object by the time this code is executed? If it crashes on the line you show make sure QApplication::style() is not nullptr. (If it could be following line, same for d->doc->documentLayout().)

        N Offline
        N Offline
        Nirbhik
        wrote on last edited by
        #3

        @JonB
        2023-12-11 18_01_04-qwidgettextcontrol.cpp - Qt Creator.png 2023-12-11 18_01_33-qwidgettextcontrol.cpp - Qt Creator.png

        JonBJ 1 Reply Last reply
        0
        • N Nirbhik

          @JonB
          2023-12-11 18_01_04-qwidgettextcontrol.cpp - Qt Creator.png 2023-12-11 18_01_33-qwidgettextcontrol.cpp - Qt Creator.png

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Nirbhik I see no stack trace, which is the most important thing.

          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