<?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[Urgent Help needed]]></title><description><![CDATA[<p dir="auto">hello i am trying to implement heaps using Qt my code displays the values of the array and then heaped function heapifys the array to give new values.</p>
<p dir="auto">the problem is i need to change color of each rect once swap takes place for example if rect 1 and rect 3 are interchanged they would change to red from yellow then swap values and then change back to normal color</p>
<p dir="auto">this is the code of my dialog</p>
<p dir="auto">@<br />
void Dialog::paintEvent(QPaintEvent *e)<br />
{</p>
<pre><code>QPainter painter(this);
QBrush brush(Qt::yellow);
 QBrush brush2(Qt::red);
QPen pen1(Qt::black);
pen1.setWidth(6);
QString str[10];


for(int a=0;a&lt;9;a++)
{
    str[a].append(QString("%1").arg(array[a]));
    QRect rec(((50*a)+50),100,50,50);
    painter.setPen(pen1);
    painter.drawRect(rec);
    painter.fillRect(rec,brush);
    painter.drawText(rec,Qt::AlignCenter,str[a]);

}
delay();
heaped();
//heapify();

QString str2[10];



for(int a=0;a&lt;9;a++)
{
    str2[a].append(QString("%1").arg(array[a]));
    QRect rec(((50*a)+50),100,50,50);
    painter.setPen(pen1);
    painter.drawRect(rec);
    painter.fillRect(rec,brush2);
    painter.drawText(rec,Qt::AlignCenter,str2[a]);


}
 repaint();

delay();
</code></pre>
<p dir="auto">}</p>
<p dir="auto">@</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/void">@<bdi>void</bdi></a> Dialog::heaped()<br />
{</p>
<pre><code>while(flag != 0)
{
    flag = 0;
    for(int i=size-1; i&gt;0; i--)
    {
        int j = i/2;

        if(array[j] &gt; array[i])
        {
            QPaintEvent *e;
            int temp = array[i];
            array[i] = array[j];
            array[j] = temp;
            flag++;
        }
    }
}
</code></pre>
<p dir="auto">}@</p>
<p dir="auto">@Dialog::Dialog(QWidget *parent) :<br />
QDialog(parent),<br />
ui(new Ui::Dialog)<br />
{<br />
flag=1;<br />
size=9;<br />
for(int i=0;i&lt;9;i++)       // code to set values randomly to the array<br />
{<br />
array[i]=(qrand()0)+1;</p>
<pre><code>}
ui-&gt;setupUi(this);
</code></pre>
<p dir="auto">}</p>
<p dir="auto">Dialog::~Dialog()<br />
{<br />
delete ui;<br />
}</p>
<p dir="auto">void Dialog::delay()            // function to give delay<br />
{<br />
QTime time=QTime::currentTime().addSecs(3);<br />
while(QTime::currentTime()&lt;time)<br />
{<br />
QCoreApplication::processEvents(QEventLoop::AllEvents,100);<br />
}</p>
<p dir="auto">}@</p>
]]></description><link>https://forum.qt.io/topic/23089/urgent-help-needed</link><generator>RSS for Node</generator><lastBuildDate>Fri, 12 Jun 2026 23:04:54 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/23089.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 11 Jan 2013 00:40:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Urgent Help needed on Fri, 11 Jan 2013 08:14:23 GMT]]></title><description><![CDATA[<p dir="auto">Also a Qt coding thing is not to use the [] operators. It's more a C thing then Qt and might cause illegal acces issues in memory. Rather use QList &lt;class T&gt; and then the <a href="http://T.at" target="_blank" rel="noopener noreferrer nofollow ugc">T.at</a>() function. The at function is better protected.<br />
Greetz</p>
]]></description><link>https://forum.qt.io/post/162688</link><guid isPermaLink="true">https://forum.qt.io/post/162688</guid><dc:creator><![CDATA[Jeroentjehome]]></dc:creator><pubDate>Fri, 11 Jan 2013 08:14:23 GMT</pubDate></item><item><title><![CDATA[Reply to Urgent Help needed on Fri, 11 Jan 2013 06:46:19 GMT]]></title><description><![CDATA[<p dir="auto">I think it is not a really good idea to do the complete color processing inside the paintevent.<br />
Especially the delay methods inside the paint event are wrong.<br />
You should do the processing outside the paintevent timertriggered in a method in the Dialog class, and control the color of your rectangles with an additional atribute.</p>
<p dir="auto">regards<br />
karl-heinz</p>
]]></description><link>https://forum.qt.io/post/162677</link><guid isPermaLink="true">https://forum.qt.io/post/162677</guid><dc:creator><![CDATA[khrl01]]></dc:creator><pubDate>Fri, 11 Jan 2013 06:46:19 GMT</pubDate></item><item><title><![CDATA[Reply to Urgent Help needed on Fri, 11 Jan 2013 00:42:51 GMT]]></title><description><![CDATA[<p dir="auto">I made a overridden function that would be called in heaped after the values are swapped so that the two swapped values could be changed to blue .. but wen i run the computer hangs</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/void">@<bdi>void</bdi></a> Dialog::paintEvent2(QPaintEvent *e,int swp1,int swp2)<br />
{</p>
<pre><code>QPainter painter(this);
QBrush brush(Qt::red);
QPen pen1(Qt::black);
pen1.setWidth(6);
QString str[10];
QBrush brush2(Qt::yellow);

for(int a=0;a&lt;9;a++)
{
    if(a!=swp1 &amp;&amp; a!=swp2)
    {

            str[a].append(QString("%1").arg(array[a]));
            QRect rec(((50*a)+50),100,50,50);
            painter.setPen(pen1);
            painter.drawRect(rec);
            painter.fillRect(rec,brush);
            painter.drawText(rec,Qt::AlignCenter,str[a]);

    }
    else
    {
        str[a].append(QString("%1").arg((array[a])));
        QRect rec2(50*a+50,100,50,50);
        painter.setPen(pen1);
        painter.drawRect(rec2);
        painter.fillRect(rec2,brush2);
        painter.drawText(rec2,Qt::AlignCenter,str[a]);


    }
</code></pre>
<p dir="auto">}</p>
<p dir="auto">}<br />
@</p>
]]></description><link>https://forum.qt.io/post/162672</link><guid isPermaLink="true">https://forum.qt.io/post/162672</guid><dc:creator><![CDATA[fahd_arshad123]]></dc:creator><pubDate>Fri, 11 Jan 2013 00:42:51 GMT</pubDate></item></channel></rss>