<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Segmentation fault in nested QOpenGLWidget]]></title><description><![CDATA[<p dir="auto">Hello.<br />
I write this post because I am really depleted of ideas. I have desktop application that has main <code>QWindow</code> with nested <code>QOpenGLWidget</code> window. Earlier to handle all this OpenGL stuff I used glut lib hovewere finally I growed up to get rid of it.<br />
Problem is now when I run my app, on the very beginnng I have segmentation fault and I really don't know why.</p>
<pre><code>int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    //the same version of context for all GL widgets
    QSurfaceFormat format;
    format.setDepthBufferSize(24);
    format.setStencilBufferSize(8);
    format.setVersion(4, 5);
    format.setProfile(QSurfaceFormat::CoreProfile);
    QSurfaceFormat::setDefaultFormat(format);

    //restores std::stof divides numbers by '.' instead of local
    std::setlocale(LC_ALL, "C");

    if (argc &gt; 2 &amp;&amp; std::string(argv[1]) == "--config")
    {
        Config(std::string(argv[2]));
    }
    else
    {
        Config();
    }

    //creation and displaying main window
    MainWindow w = new MainWindow();
    w.show();      //&lt;------ somwhere below segmentation happens

    return a.exec();
}
</code></pre>
<p dir="auto">Main window looks like this:</p>
<pre><code>MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{
    inpMan = &amp;ObjManager::getInstance();
    tm = &amp;TimelapseManager::getInstance();

    ui-&gt;setupUi(this);

    oglWindow = std::make_unique&lt;OGLWindow&gt;(qobject_cast&lt;OGLWindow*&gt;(ui-&gt;oglWindow));

    if (!oglWindow) {
        oglWindow = std::make_unique&lt;OGLWindow&gt;(new OGLWindow(this));
        ui-&gt;oglWindow-&gt;setParent(nullptr);
        ui-&gt;oglWindow-&gt;deleteLater();
        ui-&gt;centralwidget-&gt;layout()-&gt;addWidget(oglWindow.get());
    }

    initGUI();
    enableUIElements(false);

    // glutInit(argc, argv);    //&lt;----remnant of glut
}
</code></pre>
<p dir="auto">segmentation happens when <code>w.show()</code> is proceeded and statck trace looks like this:</p>
<pre><code>1  QOpenGLContext::functions() const                                                          0x7ffe7131809a 
2  QOpenGLWidget::qt_static_metacall(QObject *, QMetaObject::Call, int, void * *)             0x7ffeb7f921da 
3  QOpenGLWidget::makeCurrent(QOpenGLWidget::TargetBuffer)                                    0x7ffeb7f93798 
4  QWidget::event(QEvent *)                                                                   0x7ffe72f09d90 
5  QApplicationPrivate::notify_helper(QObject *, QEvent *)                                    0x7ffe72eb5b5c 
6  QCoreApplication::notifyInternal2(QObject *, QEvent *)                                     0x7ffe71aa73aa 
7  QWidgetPrivate::sendPaintEvent(QRegion const&amp;)                                             0x7ffe72f0113e 
8  QOpenGLWidget::resizeEvent(QResizeEvent *)                                                 0x7ffeb7f92fea 
9  QWidget::event(QEvent *)                                                                   0x7ffe72f0a417 
10 QApplicationPrivate::notify_helper(QObject *, QEvent *)                                    0x7ffe72eb5b5c 
11 QCoreApplication::notifyInternal2(QObject *, QEvent *)                                     0x7ffe71aa73aa 
12 QWidgetPrivate::sendPendingMoveAndResizeEvents(bool, bool)                                 0x7ffe72f0105b 
13 QWidgetPrivate::show_helper()                                                              0x7ffe72f06349 
14 QWidgetPrivate::setVisible(bool)                                                           0x7ffe72f094a4 
15 QWidgetPrivate::showChildren(bool)                                                         0x7ffe72f05df1 
16 QWidgetPrivate::show_helper()                                                              0x7ffe72f06366 
17 QWidgetPrivate::setVisible(bool)                                                           0x7ffe72f094a4 
18 QWidgetPrivate::showChildren(bool)                                                         0x7ffe72f05df1 
19 QWidgetPrivate::show_helper()                                                              0x7ffe72f06366 
20 QWidgetPrivate::setVisible(bool)                                                           0x7ffe72f094a4 
21 main                                                                           main.cpp 33 0x7ff641ae586f
</code></pre>
<p dir="auto">It tells me something is with context but what? During debug everything is initialized in my <code>OGLWindow::OGLWindow(QWidget *parent):QOpenGLWidget(parent)</code> window properly</p>
<pre><code>void OGLWindow::initializeGL()
{
    initializeOpenGLFunctions();

    glEnable(GL_PROGRAM_POINT_SIZE);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);

    createShaders();

    fillBufferCross();
    fillBufferScale();
}
</code></pre>
<p dir="auto">What I miss?</p>
]]></description><link>https://forum.qt.io/topic/164111/segmentation-fault-in-nested-qopenglwidget</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 11:17:51 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/164111.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 19 Jan 2026 09:29:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Segmentation fault in nested QOpenGLWidget on Mon, 02 Mar 2026 23:46:46 GMT]]></title><description><![CDATA[<p dir="auto">I found a reason.<br />
Problem was I used makeCurrent()/doneCurrent() manually in every method where I draw something using OGL.<br />
Especially in<br />
void initializeGL() override;<br />
void paintGL() override;<br />
void resizeGL(int width, int height) override;</p>
<p dir="auto">It broke context of OGL and caused crash. Probably at some moment during initialization of app it called not created context and thats it.<br />
Earlier it worked because I used additionally glut lib and most likely glut made some steps accidentaly neutralized my clumsiness.</p>
]]></description><link>https://forum.qt.io/post/836722</link><guid isPermaLink="true">https://forum.qt.io/post/836722</guid><dc:creator><![CDATA[Riwar]]></dc:creator><pubDate>Mon, 02 Mar 2026 23:46:46 GMT</pubDate></item><item><title><![CDATA[Reply to Segmentation fault in nested QOpenGLWidget on Thu, 29 Jan 2026 00:50:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
I will try to prepare it.</p>
]]></description><link>https://forum.qt.io/post/835811</link><guid isPermaLink="true">https://forum.qt.io/post/835811</guid><dc:creator><![CDATA[Riwar]]></dc:creator><pubDate>Thu, 29 Jan 2026 00:50:26 GMT</pubDate></item><item><title><![CDATA[Reply to Segmentation fault in nested QOpenGLWidget on Tue, 20 Jan 2026 17:15:45 GMT]]></title><description><![CDATA[<p dir="auto">Without a proper minimal compilable reproducer, it's going to be close to impossible to find what goes wrong.</p>
]]></description><link>https://forum.qt.io/post/835569</link><guid isPermaLink="true">https://forum.qt.io/post/835569</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 20 Jan 2026 17:15:45 GMT</pubDate></item><item><title><![CDATA[Reply to Segmentation fault in nested QOpenGLWidget on Mon, 19 Jan 2026 23:39:33 GMT]]></title><description><![CDATA[<p dir="auto">I see I cant edit such old posts. Then main window should looks like this</p>
<pre><code>MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{
    inpMan = &amp;ObjManager::getInstance();
    tm = &amp;TimelapseManager::getInstance();

    ui-&gt;setupUi(this);
    initGUI();
    enableUIElements(false);
}
</code></pre>
]]></description><link>https://forum.qt.io/post/835536</link><guid isPermaLink="true">https://forum.qt.io/post/835536</guid><dc:creator><![CDATA[Riwar]]></dc:creator><pubDate>Mon, 19 Jan 2026 23:39:33 GMT</pubDate></item><item><title><![CDATA[Reply to Segmentation fault in nested QOpenGLWidget on Mon, 19 Jan 2026 22:20:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/grecko">@<bdi>GrecKo</bdi></a> Yes. You are right about <code>make_unique</code>.<br />
This is kind of experiment. Whole this block about oglWindow is trial of replacement object done by designer with own one. At some moment I had impression the reason may whole window is not initialized at this very moment. However it acts exactly in the same manner. I will clean this.</p>
<p dir="auto">I used gdb and it clearly shows:<br />
Thread 1 received signal SIGSEGV, Segmentation fault.<br />
0x00007ffe8440809a in QOpenGLContext::functions() const () from E:\c++\RadarVis_6\app\Qt6Gui.dll</p>
]]></description><link>https://forum.qt.io/post/835535</link><guid isPermaLink="true">https://forum.qt.io/post/835535</guid><dc:creator><![CDATA[Riwar]]></dc:creator><pubDate>Mon, 19 Jan 2026 22:20:12 GMT</pubDate></item><item><title><![CDATA[Reply to Segmentation fault in nested QOpenGLWidget on Mon, 19 Jan 2026 22:06:52 GMT]]></title><description><![CDATA[<p dir="auto">FIY <code>std::make_unique</code> doesn't take a pointer and make it unique, it creates a new object and return it in a <code>unique_ptr</code>.</p>
<p dir="auto">Your code regarding <code>oglWindow</code> is very confusing.</p>
]]></description><link>https://forum.qt.io/post/835534</link><guid isPermaLink="true">https://forum.qt.io/post/835534</guid><dc:creator><![CDATA[GrecKo]]></dc:creator><pubDate>Mon, 19 Jan 2026 22:06:52 GMT</pubDate></item><item><title><![CDATA[Reply to Segmentation fault in nested QOpenGLWidget on Mon, 19 Jan 2026 21:52:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/riwar">@<bdi>Riwar</bdi></a> said in <a href="/post/835532">Segmentation fault in nested QOpenGLWidget</a>:</p>
<blockquote>
<p dir="auto">Your statement  about smart pointers suprises me. Whole world says something quiet oposite: use them man, use them!<br />
Can you extend it little bit? How can it interfere with inheritance? Finally smart pointer is just a wrapped pointer.</p>
</blockquote>
<p dir="auto">Bjarne himself recommends them but also states that as with every other tool, you have to understand when to not use them as well.</p>
<p dir="auto">In the case of Qt, see <a href="https://doc.qt.io/qt-6/objecttrees.html" target="_blank" rel="noopener noreferrer nofollow ugc">Object Trees &amp; Ownership</a>. Qt has managed the lifetime of its QObject based classes way before C++ got all these smart pointers hence their are not an appropriate tool in this context. You will get things like double deletion happening. I am not saying that this is the cause in your case as your code sample is not complete enough to test but it wont hurt to remove these. Note that there's nothing wrong with using them alongside Qt for other objects lifetime management.</p>
]]></description><link>https://forum.qt.io/post/835533</link><guid isPermaLink="true">https://forum.qt.io/post/835533</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 19 Jan 2026 21:52:29 GMT</pubDate></item><item><title><![CDATA[Reply to Segmentation fault in nested QOpenGLWidget on Mon, 19 Jan 2026 21:38:22 GMT]]></title><description><![CDATA[<p dir="auto">Hi SGaist.</p>
<p dir="auto">Win10, 64 bits, Qt 6.10.1.<br />
I work under VS Code.</p>
<p dir="auto">This is my CMakeLists</p>
<pre><code>cmake_minimum_required(VERSION 4.2)
if(POLICY CMP0167)
    cmake_policy(SET CMP0167 OLD)
endif()

project ( RadarVis )

# C++17 is needed because of toml++
set(CMAKE_CXX_STANDARD 17)

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
endif()

# Flagi kompilatora dla trybu Debug (MinGW / GCC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -DDEBUG")

# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Instruct CMake to run uic automatically when needed.
set(CMAKE_AUTOUIC ON)

set(CMAKE_AUTOUIC_SEARCH_PATHS ui/custom ui/window)

set(CPP_LIBS "e:/storage/cpp/libs")

set(BOOST_ROOT "${CPP_LIBS}/boost")
set(BOOST_INCLUDEDIR "${BOOST_ROOT}")
set(BOOST_LIBRARYDIR "${BOOST_ROOT}/libs")
set(Boost_NO_SYSTEM_PATHS ON)
find_package(Boost REQUIRED)


set(Qt6_DIR "e:/storage/cpp/Qt/6.10.1/mingw_64/lib/cmake/Qt6")
find_package(Qt6 COMPONENTS Core Widgets OpenGLWidgets Gui REQUIRED)

find_package(OpenGL REQUIRED)

file(GLOB_RECURSE SOURCES "src/*.cpp")
file(GLOB_RECURSE HEADERS "config/*.h" "gui/*.h" "input/*.h" "scene/*.h")
file(GLOB_RECURSE UI "ui/**/*.ui")


set(TARGET_NAME radarvis)

add_executable(
    ${TARGET_NAME}
    ${SOURCES}
    ${HEADERS}
    ${UI}
)

target_compile_definitions(${TARGET_NAME}
    PRIVATE
        WIN32_LEAN_AND_MEAN
)

target_include_directories(
    ${TARGET_NAME}
    PRIVATE
        ${Boost_INCLUDE_DIRS}
        ${CPP_LIBS}/glm
)

target_link_libraries(
    ${TARGET_NAME}
    PRIVATE
        Qt6::Core
        Qt6::Widgets
        Qt6::OpenGLWidgets
        Qt6::Gui

        OpenGL::GL
        opengl32

        ${Boost_LIBRARIES}
        ws2_32
)
</code></pre>
<p dir="auto">Your statement  about smart pointers suprises me. Whole world says something quiet oposite: use them man, use them!<br />
Can you extend it little bit? How can it interfere with inheritance? Finally smart pointer is just a wrapped pointer.</p>
]]></description><link>https://forum.qt.io/post/835532</link><guid isPermaLink="true">https://forum.qt.io/post/835532</guid><dc:creator><![CDATA[Riwar]]></dc:creator><pubDate>Mon, 19 Jan 2026 21:38:22 GMT</pubDate></item><item><title><![CDATA[Reply to Segmentation fault in nested QOpenGLWidget on Mon, 19 Jan 2026 19:42:17 GMT]]></title><description><![CDATA[<p dir="auto">Hi and welcome to devnet,</p>
<p dir="auto">The first thing I would do: remove all these smart pointers. They don't play well with Qt's parent child paradigm.</p>
<p dir="auto">Then, which version of Qt are you using ?<br />
Which OS are you running ?</p>
]]></description><link>https://forum.qt.io/post/835530</link><guid isPermaLink="true">https://forum.qt.io/post/835530</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 19 Jan 2026 19:42:17 GMT</pubDate></item></channel></rss>