<?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[QOpenGLWidget says I need a QApplication before QWidget, even if I already have.]]></title><description><![CDATA[<p dir="auto">So I'm making a game engine, I tried to make a QOpenGLWidget attached to one of my QMainWindow tabs, but unfortunately I kept getting an error saying I need to construct a QApplication before a QWidget.</p>
<p dir="auto">I already did that but unfortunately doesn't work.</p>
<p dir="auto">Am I doing something wrong here?</p>
<p dir="auto">LevelEditor.cpp:</p>
<pre><code>HAEDITOR_LEVELEDITOR::HAEDITOR_LEVELEDITOR(QWidget *parent)
	: QOpenGLWidget(parent)
{
	ui.setupUi(this);

	//HATime::renderAPI = HA_RENDER_ENUM::OpenGL;

	// QOpenGLWidget* oGL = new QOpenGLWidget(parent);
	ui.gridLayout-&gt;addWidget(this);

	HAEDITOR_MAINWINDOW* mainWindow = new HAEDITOR_MAINWINDOW();
	mainWindow-&gt;ui.TabNavigation-&gt;insertTab(0, this, "Level Editor");

	initializeGL();
	paintGL();
	resizeGL(1024, 716);
}
</code></pre>
<p dir="auto">MainWIndow.cpp</p>
<pre><code>HAEDITOR_MAINWINDOW::HAEDITOR_MAINWINDOW(QWidget* parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);

	HAEDITOR_LEVELEDITOR* levelEditor = new HAEDITOR_LEVELEDITOR(parent);

	ui.TabNavigation-&gt;insertTab(0, levelEditor, "Level Editor");
}
</code></pre>
<p dir="auto">Main.cpp:</p>
<pre><code>int main(int argc, char* argv[])
{
	QApplication haEditor(argc, argv);

	std::unique_ptr&lt;HAEDITOR_MAINWINDOW&gt; mainEditor(new HAEDITOR_MAINWINDOW());
	mainEditor-&gt;show();

	return haEditor.exec();
}
</code></pre>
]]></description><link>https://forum.qt.io/topic/139527/qopenglwidget-says-i-need-a-qapplication-before-qwidget-even-if-i-already-have</link><generator>RSS for Node</generator><lastBuildDate>Wed, 28 Oct 2026 01:36:03 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139527.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 23 Sep 2022 14:00:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QOpenGLWidget says I need a QApplication before QWidget, even if I already have. on Sun, 25 Sep 2022 07:50:57 GMT]]></title><description><![CDATA[<p dir="auto">Now please remove all the stuff you don't need, only derive from QOpenGLWidget and remove all the other unneeded stuff to see if it still gives the problem. Once you stripped down your program to less than 50 lines we can try it out here.</p>
]]></description><link>https://forum.qt.io/post/730081</link><guid isPermaLink="true">https://forum.qt.io/post/730081</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 25 Sep 2022 07:50:57 GMT</pubDate></item><item><title><![CDATA[Reply to QOpenGLWidget says I need a QApplication before QWidget, even if I already have. on Sun, 25 Sep 2022 06:56:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/hyperspider-software">@<bdi>Hyperspider-Software</bdi></a><br />
If this were your <em>complete</em> <code>main.cpp</code> it would not compile since it does not have any <code>#include</code> statements, and nor would it have a "Line 29" as shown in the stack trace.</p>
]]></description><link>https://forum.qt.io/post/730075</link><guid isPermaLink="true">https://forum.qt.io/post/730075</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sun, 25 Sep 2022 06:56:01 GMT</pubDate></item><item><title><![CDATA[Reply to QOpenGLWidget says I need a QApplication before QWidget, even if I already have. on Sat, 24 Sep 2022 23:26:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> here:</p>
<pre><code>int main(int argc, char *argv[])
{
	QApplication haEditor(argc, argv);
	haEditor.setWindowIcon(QIcon
	("C:\\Users\\abora\\source\\repos\\HyperArachnid\\HAEditor\\Main\\Icon\\HyperArachnidLogo.png")
	);

	//std::unique_ptr&lt;HATime&gt; time(new HATime());

	QSplashScreen* splashScreen = new QSplashScreen;
	splashScreen-&gt;setPixmap(QPixmap("C:\\Users\\abora\\source\\repos\\HyperArachnid\\HAEditor\\Main\\SplashImage\\HAEditorSplashIMage.png"));
	splashScreen-&gt;show();

	QTimer::singleShot(2500, splashScreen, SLOT(close()));

	HAEDITOR_MAINWINDOW* mainEditor = new HAEDITOR_MAINWINDOW();

	HAEDITOR_LEVELGRAPH* levelEditor = new HAEDITOR_LEVELGRAPH();

	mainEditor-&gt;ui.TabNavigation-&gt;addTab(levelEditor-&gt;window(), "Level Editor");

	QTimer::singleShot(3500, mainEditor, SLOT(show()));

	return haEditor.exec();
}
</code></pre>
]]></description><link>https://forum.qt.io/post/730065</link><guid isPermaLink="true">https://forum.qt.io/post/730065</guid><dc:creator><![CDATA[Hyperspider Software]]></dc:creator><pubDate>Sat, 24 Sep 2022 23:26:35 GMT</pubDate></item><item><title><![CDATA[Reply to QOpenGLWidget says I need a QApplication before QWidget, even if I already have. on Sat, 24 Sep 2022 06:18:51 GMT]]></title><description><![CDATA[<p dir="auto">Please show your complete main.cpp - the line number in the stack trace do not match your main.cpp you posted.</p>
]]></description><link>https://forum.qt.io/post/730014</link><guid isPermaLink="true">https://forum.qt.io/post/730014</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 24 Sep 2022 06:18:51 GMT</pubDate></item><item><title><![CDATA[Reply to QOpenGLWidget says I need a QApplication before QWidget, even if I already have. on Fri, 23 Sep 2022 21:30:41 GMT]]></title><description><![CDATA[<p dir="auto">I kept seeing this message in the stack menu but couldn't find a solution.<br />
Any other solutions?</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/ab05218b-7457-4157-acde-f93aa0d2a9da.png" alt="QtProblem.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/730004</link><guid isPermaLink="true">https://forum.qt.io/post/730004</guid><dc:creator><![CDATA[Hyperspider Software]]></dc:creator><pubDate>Fri, 23 Sep 2022 21:30:41 GMT</pubDate></item><item><title><![CDATA[Reply to QOpenGLWidget says I need a QApplication before QWidget, even if I already have. on Fri, 23 Sep 2022 18:30:49 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/hyperspider-software">@<bdi>Hyperspider-Software</bdi></a> said in <a href="/post/729961">QOpenGLWidget says I need a QApplication before QWidget, even if I already have.</a>:</p>
<blockquote>
<p dir="auto">initializeGL();<br />
paintGL();<br />
resizeGL(1024, 716);</p>
</blockquote>
<p dir="auto">Beside what <a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> suggests, this is also wrong. These methods will be called when appropriate by Qt. Their place is not in the class constructor.</p>
]]></description><link>https://forum.qt.io/post/729988</link><guid isPermaLink="true">https://forum.qt.io/post/729988</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 23 Sep 2022 18:30:49 GMT</pubDate></item><item><title><![CDATA[Reply to QOpenGLWidget says I need a QApplication before QWidget, even if I already have. on Fri, 23 Sep 2022 14:03:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/hyperspider-software">@<bdi>Hyperspider-Software</bdi></a><br />
Hello and welcome.</p>
<p dir="auto">Run in debugger and look at <em>stack view</em> on error.  Usually this mean you have some static <code>QWidget</code> somewhere, at global scope, maybe in another file.  You must not do that, as it executes before your <code>main()</code> &amp; <code>QApplication</code>.</p>
]]></description><link>https://forum.qt.io/post/729962</link><guid isPermaLink="true">https://forum.qt.io/post/729962</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 23 Sep 2022 14:03:56 GMT</pubDate></item></channel></rss>