guys i need the progress bar to vary the values...(i.e)i have a label which shows the random numbers. i need the signal from the label to the progressbar...
each time the number changes the progress bar must change the value..
help me with a code..
guys i need the progress bar to vary the values...(i.e)i have a label which shows the random numbers. i need the signal from the label to the progressbar...
each time the number changes the progress bar must change the value..
help me with a code..
Last edited by CAFFRY; 28th December 2016 at 12:07.
go to "edit signals/slots" and connect your label to the progress bar by clicking on the label and dragging the cursor to the progress bar. then choose "ValueChanged(int)" and "SetValue(int)" then click OK.
I don't know much of Qt but this should work.
Last edited by daud anjum; 29th December 2016 at 13:32.
No, it won't work. QLabel does not have a signal called "ValueChanged()" (and QProgressBar doesn't have a slot named "SetValue()", but it -does- have one named "setValue()").I don't know much of Qt but this should work
How are you setting the number as the text for the label? Using a signal emitted by the part of your program that generates the "random numbers"? If so, then if the signal is sending an "int" argument, simply connect this signal to the progress bar's setValue() slot. If your signal sends a QString, then you can implement your own slot that converts the string into a number (QString::toInt() or QString::toLong()) and then calls setValue() directly on the progress bar instance.each time the number changes the progress bar must change the value.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
CAFFRY (30th December 2016)
this is my random code...
srand ( time(NULL));
int randnumber = rand() %100 + 1;
for(int i=0;i>=100;i++)
{
i = qrand();
}
QString str;
str.append(QString("%1").arg(randnumber));
ui->percentage->setText(str + "%");
if(randnumber<0)
{
QMessageBox::about(this,"error","runagain");
}
i need this to connect with the progressbar...
it would me nice if u send me the code for that connection
What the heck is this code supposed to do? It's nonsense, and in any case you shouldn't change the value of the loop iterator (i) inside the loop.for(int i=0;i>=100;i++)
{
i = qrand();
}
So how hard is that? You have an int random number, QProgressBar::setValue() is a method that takes an int argument, so if you have a UI widget named "progress" or something like that... You figured out how to set the text on the label, you should be able to figure out how to set the value on the progress bar.i need this to connect with the progressbar...
Integers returned by the rand() function are always between 0 and RAND_MAX, so this statement will never be true. And your random numbers will always be between 1 and 100 because of the modulus operation (%) you do on the value returned by rand().if(randnumber<0)
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
can u write me a code for that, for the connection between the progressbar and the label value.
and use the random code which i used ...plzzz..
and thanks for the rply
its not working
That doesn't tell us much. Post your latest code and we will take a look.its not working
By the way, this forum is not here to write your code for you. Everyone here is willing to help, but only if you try first and get stuck. We expect you to read the Qt documentation, look at the Qt tutorial and example programs, and try to solve problems yourself first. There are plenty of places in the Qt examples where basic widgets like QProgressBar and QLabel are used. If you study the examples, you might find how to do exactly what you need.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Bookmarks