<?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[Run-time error &quot;index out of range&quot;]]></title><description><![CDATA[<p dir="auto">Hi all,</p>
<p dir="auto">I fighting with a nasty problem on my Windows port (VS2008/VC++v9) for a test-tool with 2 threads.<br />
To give you an overview what I did:</p>
<p dir="auto">MainThread (keeps fingers on the Display/Input-Events)<br />
WorkerThread (did some serial communication)</p>
<p dir="auto">MainThread send commands by QQueue to the WorkerThread to tell what command to execute.<br />
WorkerThread uses signal/slot to update the MainThreads QListWidget, QTextEdit, QLineEdit ....</p>
<p dir="auto">What happen under Windows, the WorkerThread use a signal to clear a logging window (QListWidget). Next it write some debug<br />
info's into it.  ASSERT QVector&lt;T&gt;::at: "index out of range".            (SOMETIMES)</p>
<p dir="auto">When I debug the session and go back in the call-stack and check the variables  i(1)  and d-&gt;size(20) the Assert condition<br />
not match any more ( i &gt; 0 &amp;&amp; i &lt; d-&gt;size ).</p>
<p dir="auto">My workaround I sleep for 200ms after the QListWidget::clear() before I continue with the program.</p>
<p dir="auto">Not working: use a Mutex to protect the update calls in the MainThread to manipulate the display.</p>
<p dir="auto">Mainthread queue in:<br />
@<br />
void Reader::freqSetPreset()<br />
{<br />
Cmd cmd;<br />
cmd.cnum = Cmd::PRESETFREQ;<br />
cmd.freqMode = ( cbFrePreset-&gt;currentIndex() &amp; 0xff );<br />
_thread1.queueCmd(cmd);<br />
}<br />
@</p>
<p dir="auto">WorkerThread Dequeue<br />
@<br />
worker::run(){<br />
....<br />
forever {<br />
_mutex.lock();<br />
if ( _run ) {<br />
_mutex.unlock();<br />
if ( _cmdqueue.isEmpty() ) {<br />
usleep(100);<br />
}<br />
else {</p>
<pre><code>_queuemutex.lock();
Cmd cmd = _cmdqueue.dequeue();
_queuemutex.unlock();
</code></pre>
<p dir="auto">...<br />
switch ( cmd ) {<br />
case Cmd::PRESETFREQ:<br />
{<br />
qDebug("Thread1 PresetFeq");<br />
clearlog();<br />
// workaround<br />
usleep(200000);<br />
freqSetPreset(cmd.freqMode);<br />
break;<br />
}</p>
<p dir="auto">...</p>
<p dir="auto">void Worker::freqSetPreset(const quint8 FreMode)<br />
{<br />
...<br />
if ( _rmu.SetFrequency( FreMode, FreBase, BaseFre, ChannNum, ChannSpc, FreHop ) ) {<br />
updateStatus("Preset Frequency\tOK");   // signal<br />
}</p>
<p dir="auto">@</p>
<p dir="auto">successions welcome.</p>
<p dir="auto">Chris</p>
]]></description><link>https://forum.qt.io/topic/5715/run-time-error-index-out-of-range</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Jul 2026 19:01:48 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/5715.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 11 May 2011 08:53:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Run-time error &quot;index out of range&quot; on Thu, 12 May 2011 07:01:30 GMT]]></title><description><![CDATA[<p dir="auto">Hi All,</p>
<p dir="auto">I found the my problem. The Logging !<br />
I have my own MessageOutHandler .. this Handler wrote non synchronized directly to the ListWidget and triggers the ASSERT() .. - no need for the work around any more.</p>
<p dir="auto">Volker the article you refer was very nice. Some of the infos help me find my fault.</p>
<p dir="auto">cheers<br />
Chris</p>
]]></description><link>https://forum.qt.io/post/87577</link><guid isPermaLink="true">https://forum.qt.io/post/87577</guid><dc:creator><![CDATA[ruehlchr]]></dc:creator><pubDate>Thu, 12 May 2011 07:01:30 GMT</pubDate></item><item><title><![CDATA[Reply to Run-time error &quot;index out of range&quot; on Wed, 11 May 2011 10:30:00 GMT]]></title><description><![CDATA[<p dir="auto">Enjoy your "Feierabend" :-)</p>
]]></description><link>https://forum.qt.io/post/87439</link><guid isPermaLink="true">https://forum.qt.io/post/87439</guid><dc:creator><![CDATA[goetz]]></dc:creator><pubDate>Wed, 11 May 2011 10:30:00 GMT</pubDate></item><item><title><![CDATA[Reply to Run-time error &quot;index out of range&quot; on Wed, 11 May 2011 10:19:05 GMT]]></title><description><![CDATA[<p dir="auto">Volker,</p>
<p dir="auto">That's a succession ..<br />
thanks I will dig in - <em>windows macht mich fertig!</em>.</p>
<p dir="auto">But its 6:15pm in Hong Kong now and I go and have a beer. This problem needs to wait until tomorrow , but I let you know.</p>
<p dir="auto">Cheers<br />
Chris</p>
]]></description><link>https://forum.qt.io/post/87437</link><guid isPermaLink="true">https://forum.qt.io/post/87437</guid><dc:creator><![CDATA[ruehlchr]]></dc:creator><pubDate>Wed, 11 May 2011 10:19:05 GMT</pubDate></item><item><title><![CDATA[Reply to Run-time error &quot;index out of range&quot; on Wed, 11 May 2011 10:14:21 GMT]]></title><description><![CDATA[<p dir="auto">Could be an issue with non-queued signals between threads. Did you read Peppe's great wiki article "Threads, Events and QObjects":<a href="http://developer.qt.nokia.com/wiki/Threads_Events_QObjects" target="_blank" rel="noopener noreferrer nofollow ugc">http://developer.qt.nokia.com/wiki/Threads_Events_QObjects</a> already? It explains a lot of stuff in this area.</p>
]]></description><link>https://forum.qt.io/post/87436</link><guid isPermaLink="true">https://forum.qt.io/post/87436</guid><dc:creator><![CDATA[goetz]]></dc:creator><pubDate>Wed, 11 May 2011 10:14:21 GMT</pubDate></item><item><title><![CDATA[Reply to Run-time error &quot;index out of range&quot; on Wed, 11 May 2011 09:43:18 GMT]]></title><description><![CDATA[<p dir="auto">Franz,</p>
<p dir="auto">I need to start the thing in the Virtual Studio ( ;-( ) ) then I can tell exactly.</p>
<p dir="auto">General<br />
a) QListWidget::clear()<br />
b) QListWidget::addItem(s)    QString s</p>
<p dir="auto">sender WorkerThread via signal to receiver MainThread slot.</p>
<p dir="auto">I never face the problem on the Linux.</p>
]]></description><link>https://forum.qt.io/post/87424</link><guid isPermaLink="true">https://forum.qt.io/post/87424</guid><dc:creator><![CDATA[ruehlchr]]></dc:creator><pubDate>Wed, 11 May 2011 09:43:18 GMT</pubDate></item><item><title><![CDATA[Reply to Run-time error &quot;index out of range&quot; on Wed, 11 May 2011 09:21:05 GMT]]></title><description><![CDATA[<p dir="auto">Where exactly in the above code does your program crash?</p>
]]></description><link>https://forum.qt.io/post/87419</link><guid isPermaLink="true">https://forum.qt.io/post/87419</guid><dc:creator><![CDATA[Franzk]]></dc:creator><pubDate>Wed, 11 May 2011 09:21:05 GMT</pubDate></item></channel></rss>