<?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[label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor]]></title><description><![CDATA[<p dir="auto">.h file:</p>
<pre><code>class ImageScrollArea : public QScrollArea
{
	Q_OBJECT

public:
	explicit ImageScrollArea(QWidget *parent = nullptr);
	~ImageScrollArea() = default;

public:
	void SetImage(const QPixmap&amp; pixmap);

private:
	QLabel* m_imageLabel;
};
</code></pre>
<p dir="auto">.cpp file:</p>
<pre><code>ImageScrollArea::ImageScrollArea(QWidget* parent)
	: QScrollArea(parent)
	, m_imageLabel(new QLabel)
{
	setWidget(m_imageLabel);
}

void ImageScrollArea::SetImage(const QPixmap&amp; pixmap)
{
	if (pixmap.isNull())
		return;

	m_imageLabel-&gt;setPixmap(pixmap);
}
</code></pre>
<pre><code>The inferior stopped because it received a signal from the operating system.

Signal name :  SIGSEGV
Signal meaning :  Segmentation fault
</code></pre>
<p dir="auto">But if calling setWidget inside of SetImage everything is fine:</p>
<pre><code>void ImageScrollArea::SetImage(const QPixmap&amp; pixmap)
{
	if (pixmap.isNull())
		return;

	setWidget(m_imageLabel); // &lt;-- calling here instead of constructor
	m_imageLabel-&gt;setPixmap(pixmap);
}
</code></pre>
<p dir="auto">Any idea why?</p>
]]></description><link>https://forum.qt.io/topic/127104/label-setpixmap-causes-crash-when-is-used-after-myscrollarea-calls-setwidget-label-inside-of-constructor</link><generator>RSS for Node</generator><lastBuildDate>Thu, 18 Jun 2026 23:31:19 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/127104.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 29 May 2021 08:51:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor on Sat, 29 May 2021 21:02:47 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
If you dont need to set scrollarea properties in Designer you can also just<br />
promote a plain QWidget and hence don't get this issue.</p>
]]></description><link>https://forum.qt.io/post/662324</link><guid isPermaLink="true">https://forum.qt.io/post/662324</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Sat, 29 May 2021 21:02:47 GMT</pubDate></item><item><title><![CDATA[Reply to label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor on Sat, 29 May 2021 14:00:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rian-firth">@<bdi>Rian-Firth</bdi></a> said in <a href="/post/662280">label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor</a>:</p>
<blockquote>
<p dir="auto">I'm not sure if it's a proper way but removing scrollAreaWidgetContents directly from .ui file helps as well.</p>
</blockquote>
<p dir="auto">Modifying an ui file manually is never a good idea and for sure no solution.</p>
]]></description><link>https://forum.qt.io/post/662284</link><guid isPermaLink="true">https://forum.qt.io/post/662284</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 29 May 2021 14:00:47 GMT</pubDate></item><item><title><![CDATA[Reply to label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor on Sat, 29 May 2021 13:39:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a>, thank you so much for your help.</p>
]]></description><link>https://forum.qt.io/post/662282</link><guid isPermaLink="true">https://forum.qt.io/post/662282</guid><dc:creator><![CDATA[Rian Firth]]></dc:creator><pubDate>Sat, 29 May 2021 13:39:32 GMT</pubDate></item><item><title><![CDATA[Reply to label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor on Sat, 29 May 2021 13:22:58 GMT]]></title><description><![CDATA[<p dir="auto">I'm not sure if it's a proper way but removing <code>scrollAreaWidgetContents</code> directly from .ui file helps as well.</p>
<pre><code>    &lt;item&gt;
     &lt;widget class="ImageScrollArea" name="imageScrollArea"&gt;
      &lt;property name="widgetResizable"&gt;
       &lt;bool&gt;true&lt;/bool&gt;
      &lt;/property&gt;
      &lt;widget class="QWidget" name="scrollAreaWidgetContents"&gt;
       &lt;property name="geometry"&gt;
        &lt;rect&gt;
         &lt;x&gt;0&lt;/x&gt;
         &lt;y&gt;0&lt;/y&gt;
         &lt;width&gt;780&lt;/width&gt;
         &lt;height&gt;538&lt;/height&gt;
        &lt;/rect&gt;
       &lt;/property&gt;
      &lt;/widget&gt;
     &lt;/widget&gt;
    &lt;/item&gt;
</code></pre>
]]></description><link>https://forum.qt.io/post/662280</link><guid isPermaLink="true">https://forum.qt.io/post/662280</guid><dc:creator><![CDATA[Rian Firth]]></dc:creator><pubDate>Sat, 29 May 2021 13:22:58 GMT</pubDate></item><item><title><![CDATA[Reply to label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor on Sat, 29 May 2021 13:15:15 GMT]]></title><description><![CDATA[<p dir="auto">As I already guessed. setWidget() is called two times</p>
<pre><code>imageScrollArea-&gt;setWidget(scrollAreaWidgetContents);
</code></pre>
<p dir="auto">When creating it via designer a default widget is already said to the scroll area. Add you label to this instead calling setWidget()</p>
]]></description><link>https://forum.qt.io/post/662279</link><guid isPermaLink="true">https://forum.qt.io/post/662279</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 29 May 2021 13:15:15 GMT</pubDate></item><item><title><![CDATA[Reply to label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor on Sat, 29 May 2021 13:11:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a></p>
<p dir="auto">Okay, I got it. In <code>ui_MainWindow.h</code> there's:</p>
<pre><code>imageScrollArea-&gt;setWidget(scrollAreaWidgetContents);
</code></pre>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/0862b39e-8196-4c5b-adb2-47b593a0050b.png" alt="fb2ab2c2-7313-4f32-9fe2-a931908b2779-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Is there a way to get rid of scrollAreaWidgetContents? Am I using QScrollArea in a wrong way?</p>
]]></description><link>https://forum.qt.io/post/662278</link><guid isPermaLink="true">https://forum.qt.io/post/662278</guid><dc:creator><![CDATA[Rian Firth]]></dc:creator><pubDate>Sat, 29 May 2021 13:11:13 GMT</pubDate></item><item><title><![CDATA[Reply to label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor on Sat, 29 May 2021 12:48:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> said in <a href="/post/662274">label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor</a>:</p>
<blockquote>
<p dir="auto">And you're sure you call setWidget() only once?</p>
</blockquote>
<p dir="auto">Yup, calling setWidget() only in my custom ScrollArea's constructor.</p>
<blockquote>
<p dir="auto">Please remove all other stuff to try to create a small reproducable example.</p>
</blockquote>
<p dir="auto"><a href="https://mega.nz/file/owtigShT#1M63GDHVPDqzct7i47UV5y1lRxJWjGe-lfGJwYqqgw4" target="_blank" rel="noopener noreferrer nofollow ugc">https://mega.nz/file/owtigShT#1M63GDHVPDqzct7i47UV5y1lRxJWjGe-lfGJwYqqgw4</a></p>
]]></description><link>https://forum.qt.io/post/662276</link><guid isPermaLink="true">https://forum.qt.io/post/662276</guid><dc:creator><![CDATA[Rian Firth]]></dc:creator><pubDate>Sat, 29 May 2021 12:48:04 GMT</pubDate></item><item><title><![CDATA[Reply to label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor on Sat, 29 May 2021 12:24:10 GMT]]></title><description><![CDATA[<p dir="auto">And you're sure you call setWidget() only once? Please remove all other stuff to try to create a small reproducable example.</p>
]]></description><link>https://forum.qt.io/post/662274</link><guid isPermaLink="true">https://forum.qt.io/post/662274</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 29 May 2021 12:24:10 GMT</pubDate></item><item><title><![CDATA[Reply to label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor on Sat, 29 May 2021 12:14:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a></p>
<pre><code>1  QLabel::setPixmap(QPixmap const&amp;)                                                                                                                                                                      0x10d252c  
2  ImageScrollArea::SetImage                                                                                                                                                      ImageScrollArea.cpp 18  0x401668   
3  MainWindow::&lt;lambda()&gt;::operator()(void) const                                                                                                                                 MainWindow.cpp      14  0x401850   
4  QtPrivate::FunctorCall&lt;QtPrivate::IndexesList&lt;&gt;, QtPrivate::List&lt;&gt;, void, MainWindow::MainWindow(QWidget *)::&lt;lambda()&gt;&gt;::call(MainWindow::&lt;lambda()&gt; &amp;, void * *)             qobjectdefs_impl.h  146 0x401cb8   
5  QtPrivate::Functor&lt;MainWindow::MainWindow(QWidget *)::&lt;lambda()&gt;, 0&gt;::call&lt;QtPrivate::List&lt;&gt;, void&gt;(MainWindow::&lt;lambda()&gt; &amp;, void *, void * *)                                qobjectdefs_impl.h  256 0x401c98   
6  QtPrivate::QFunctorSlotObject&lt;MainWindow::MainWindow(QWidget *)::&lt;lambda()&gt;, 0, QtPrivate::List&lt;&gt;, void&gt;::impl(int, QtPrivate::QSlotObjectBase *, QObject *, void * *, bool *) qobjectdefs_impl.h  443 0x401c69   
7  void doActivate&lt;false&gt;(QObject *, int, void * *)                                                                                                                                                       0x68b99915 
8  QAction::activate(QAction::ActionEvent)                                                                                                                                                                0xfb3df3   
9  QMenuPrivate::activateCausedStack(QVector&lt;QPointer&lt;QWidget&gt;&gt; const&amp;, QAction *, QAction::ActionEvent, bool)                                                                                            0x110c4eb  
10 QMenuPrivate::activateAction(QAction *, QAction::ActionEvent, bool)                                                                                                                                    0x1112572  
11 QMenu::mouseReleaseEvent(QMouseEvent *)                                                                                                                                                                0x1113459  
12 QWidget::event(QEvent *)                                                                                                                                                                               0xff3d78   
13 QMenu::event(QEvent *)                                                                                                                                                                                 0x111564e  
14 QApplicationPrivate::notify_helper(QObject *, QEvent *)                                                                                                                                                0xfb790e   
15 QApplication::notify(QObject *, QEvent *)                                                                                                                                                              0xfbf1ea   
16 QCoreApplication::sendSpontaneousEvent(QObject *, QEvent *)                                                                                                                                            0x68a65588 
17 QApplicationPrivate::sendMouseEvent(QWidget *, QMouseEvent *, QWidget *, QWidget *, QWidget * *, QPointer&lt;QWidget&gt;&amp;, bool, bool)                                                                       0xfbd83b   
18 QWidgetWindow::handleMouseEvent(QMouseEvent *)                                                                                                                                                         0x100a37e  
19 QWidgetWindow::event(QEvent *)                                                                                                                                                                         0x100cc06  
20 QApplicationPrivate::notify_helper(QObject *, QEvent *)                                                                                                                                                0xfb790e   
21 QApplication::notify(QObject *, QEvent *)                                                                                                                                                              0xfbe3e3   
22 QCoreApplication::sendSpontaneousEvent(QObject *, QEvent *)                                                                                                                                            0x68a65588 
23 QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *)                                                                                                                 0x61979ff4 
24 QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *)                                                                                                   0x6197b315 
25 QWindowSystemInterface::sendWindowSystemEvents(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;)                                                                                                                  0x6195726c 
26 QEventDispatcherWin32::processEvents(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;)                                                                                                                            0x68abb6c0 
27 QWindowsGuiEventDispatcher::processEvents(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;)                                                                                                                       0x6a903e85 
28 QEventLoop::exec(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;)                                                                                                                                                0x68a63a15 
29 QCoreApplication::exec()                                                                                                                                                                               0x68a6cd75 
30 qMain                                                                                                                                                                          main.cpp            10  0x4016e0   
31 WinMain                                                                                                                                                                        qtmain_win.cpp      97  0x40390d   
32 __tmainCRTStartup                                                                                                                                                                                      0x4013c7   
33 WinMainCRTStartup                                                                                                                                                                                      0x4014cb   
</code></pre>
<p dir="auto">Also I found "Create Full Backtrace" option. Is it needed?</p>
]]></description><link>https://forum.qt.io/post/662273</link><guid isPermaLink="true">https://forum.qt.io/post/662273</guid><dc:creator><![CDATA[Rian Firth]]></dc:creator><pubDate>Sat, 29 May 2021 12:14:23 GMT</pubDate></item><item><title><![CDATA[Reply to label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor on Sat, 29 May 2021 11:58:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> said in <a href="/post/662270">label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor</a>:</p>
<blockquote>
<p dir="auto">post the backtrace maybe?</p>
</blockquote>
<p dir="auto">I'm sorry, that's the part I don't understand the most. I don't get what you mean by backtrace and where I can see it in qtc.<br />
Is call stack (the screen I sent before) not the same as backtrace?</p>
]]></description><link>https://forum.qt.io/post/662271</link><guid isPermaLink="true">https://forum.qt.io/post/662271</guid><dc:creator><![CDATA[Rian Firth]]></dc:creator><pubDate>Sat, 29 May 2021 11:58:53 GMT</pubDate></item><item><title><![CDATA[Reply to label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor on Sat, 29 May 2021 11:55:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rian-firth">@<bdi>Rian-Firth</bdi></a> Use a debugger, let it run until it crashes, post the backtrace maybe?</p>
]]></description><link>https://forum.qt.io/post/662270</link><guid isPermaLink="true">https://forum.qt.io/post/662270</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 29 May 2021 11:55:10 GMT</pubDate></item><item><title><![CDATA[Reply to label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor on Sat, 29 May 2021 11:44:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> said in <a href="/post/662265">label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor</a>:</p>
<blockquote>
<p dir="auto">And what's the backtrace when it crashes?</p>
</blockquote>
<p dir="auto">How do I check that?</p>
]]></description><link>https://forum.qt.io/post/662268</link><guid isPermaLink="true">https://forum.qt.io/post/662268</guid><dc:creator><![CDATA[Rian Firth]]></dc:creator><pubDate>Sat, 29 May 2021 11:44:04 GMT</pubDate></item><item><title><![CDATA[Reply to label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor on Sat, 29 May 2021 11:33:01 GMT]]></title><description><![CDATA[<p dir="auto">And what's the backtrace when it crashes?</p>
]]></description><link>https://forum.qt.io/post/662265</link><guid isPermaLink="true">https://forum.qt.io/post/662265</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 29 May 2021 11:33:01 GMT</pubDate></item><item><title><![CDATA[Reply to label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor on Sat, 29 May 2021 10:04:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a></p>
<p dir="auto">MainWindow.cpp</p>
<pre><code>MainWindow::MainWindow(QWidget* parent)
	: QMainWindow(parent)
	, m_ui(std::make_unique&lt;Ui::MainWindow&gt;())
{
	m_ui-&gt;setupUi(this);

	connect(m_ui-&gt;actionOpen, &amp;QAction::triggered, this, [this]() {
		auto filename = QFileDialog::getOpenFileName(this, "Open", "", "Images (*.png *.jpg)");
		m_ui-&gt;imageScrollArea-&gt;SetImage(QPixmap(filename)); // &lt;-- SetImage call is here
	});
}

MainWindow::~MainWindow()
{
}
</code></pre>
<p dir="auto">Also what exactly do you mean by backtrace?<br />
Call stack is fine?<br />
<img src="https://ddgobkiprc33d.cloudfront.net/f7d9d754-051f-4bf0-8935-9fa04e03f8b4.png" alt="6f51d512-094c-48b5-a31a-8b918c5b8e04-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/662258</link><guid isPermaLink="true">https://forum.qt.io/post/662258</guid><dc:creator><![CDATA[Rian Firth]]></dc:creator><pubDate>Sat, 29 May 2021 10:04:02 GMT</pubDate></item><item><title><![CDATA[Reply to label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor on Sat, 29 May 2021 09:23:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rian-firth">@<bdi>Rian-Firth</bdi></a> said in <a href="/post/662248">label-&gt;setPixmap causes crash when is used after MyScrollArea calls setWidget(label) inside of constructor</a>:</p>
<blockquote>
<p dir="auto">Any idea why?</p>
</blockquote>
<p dir="auto">From where do you call SetImage? Please also show the backtrace.</p>
]]></description><link>https://forum.qt.io/post/662254</link><guid isPermaLink="true">https://forum.qt.io/post/662254</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 29 May 2021 09:23:06 GMT</pubDate></item></channel></rss>