Program Crashes giving segmentation fault as an error
-
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 )
-
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 )
@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 sureQApplication::style()
is notnullptr
. (If it could be following line, same ford->doc->documentLayout()
.) -
@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 sureQApplication::style()
is notnullptr
. (If it could be following line, same ford->doc->documentLayout()
.)