<?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[problems with Qt::QueuedConnection]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I am pretty sure it is an easy error or a general misunderstanding but I don't see it so I am posting here.</p>
<p dir="auto">I have a  MainWindow class which holds a Sync object and a Logger object.</p>
<p dir="auto">After a action is triggered a function in the mainwindow starts a function from the sync object in another thread. (std::thread).<br />
e.g.: std::thread a(&amp;Sync::startSyncProcess,sync_.get());<br />
The thread is immediately detached.</p>
<p dir="auto">The sync Objects holds a pointer to a log object which holds pointers to all objects that needs information about the sync process.<br />
The "Logger" is a QObject with a Q_Object macro.<br />
The sync objects calls a Logger::report(int step) function which emits a Logger::report_progress_to_mwnd(step) function.</p>
<p dir="auto">In the Constructor of the Logger I made a Qt::QueuedConnection between the Logger::report and Logger::reports_progress_to_mwnd function.</p>
<p dir="auto">Here is the basic code:</p>
<pre><code class="language-cpp">class Logger : public QObject
{
	Q_OBJECT
public:
	Logger(QProgressBar * mwpb) : mw_pb_(mwpb)
	{
		QObject::connect(this, SIGNAL(report(int)), this, SLOT(report_progress_to_mwnd(int)), Qt::QueuedConnection);
	}
	void report(int step){ 
		emit(report_progress_to_mwnd(step)); 
	}
	void report_progress_to_mwnd(int steps)
	{
		mw_pb_-&gt;setMinimum(0);
		mw_pb_-&gt;setMaximum(5);
		mw_pb_-&gt;setValue(steps);
	}
};
</code></pre>
<p dir="auto">I thought that the report_progress_to_mwnd(int steps); function would be emited in the Thread of the MainWindow but it is still executed in the thread that I launched from the MainWindow. What do I oversee?</p>
<p dir="auto">Please do not recommend to change std::thread with QThread I need a solution with std::threads.</p>
<p dir="auto">Thanks for your help.</p>
<p dir="auto">Regards,<br />
Revi</p>
]]></description><link>https://forum.qt.io/topic/53662/problems-with-qt-queuedconnection</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Apr 2026 19:27:26 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/53662.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 26 Apr 2015 13:05:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to problems with Qt::QueuedConnection on Sun, 26 Apr 2015 17:12:13 GMT]]></title><description><![CDATA[<p dir="auto">Thank you very much for the clarification that solved my problem.</p>
]]></description><link>https://forum.qt.io/post/271610</link><guid isPermaLink="true">https://forum.qt.io/post/271610</guid><dc:creator><![CDATA[Revi]]></dc:creator><pubDate>Sun, 26 Apr 2015 17:12:13 GMT</pubDate></item><item><title><![CDATA[Reply to problems with Qt::QueuedConnection on Sun, 26 Apr 2015 16:05:28 GMT]]></title><description><![CDATA[<p dir="auto">Hi, welcome to devnet.</p>
<p dir="auto">That's not how you define signals and slots and emitting a slot makes no sense.</p>
<pre><code class="language-cpp">class Logger : public QObject
{
   Q_OBJECT
public:
   Logger(QProgressBar * mwpb) : mw_pb_(mwpb) {
       connect(this, SIGNAL(reported(int)), this, SLOT(report_progress_to_mwnd(int)), Qt::QueuedConnection);
   }
   void report(int step) {
      emit reported(step); //you emit a signal, not a slot
   }

signals:
   void reported(int); //you don't implement signals. they are generated by moc

public slots:
   void report_progress_to_mwnd(int steps) {
      mw_pb_-&gt;setMinimum(0);
      mw_pb_-&gt;setMaximum(5);
      mw_pb_-&gt;setValue(steps);
   }
};
</code></pre>
<p dir="auto">Now calling a <code>report</code> method will emit signal <code>reported</code>and that in turn will schedule the connected <code>report_progress_to_mwnd</code> slot to execute.</p>
<p dir="auto">Btw. Please use ``` at the beginning and end of code blocks to enable code highlighter.</p>
]]></description><link>https://forum.qt.io/post/271605</link><guid isPermaLink="true">https://forum.qt.io/post/271605</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Sun, 26 Apr 2015 16:05:28 GMT</pubDate></item></channel></rss>