QProgressbar does not respond to large values - qt

I want to build an application that calculates large computations using an idle timer. The progress bar works fine for small numbers but if I enter large numbers as input the progress bar does not display anything.
Code, where I set the QProgressbar, is as shown below.
void MainWindow::on_startButton_clicked()
{
numberEntered = ui->inputValue->text().toInt();
QIntValidator * validator = new QIntValidator(this);
ui->inputValue->setValidator(validator);
ui->progressBar->setMaximum(numberEntered);
globalIndex = 0;
timer->start(0);
ui->resultArea->append(QString("STARTED"));
}
and in another place
void MainWindow::countManager()
{
if(globalIndex == 0){
ui->resultArea->append(QString("%1 : is a Prime number").arg(globalIndex));
ui->progressBar->setValue(globalIndex);
}
if(globalIndex <= numberEntered && globalIndex != 0){
int result = primeNumberCalculator(globalIndex);
ui->progressBar->setValue(globalIndex);
if(result !=0){
ui->resultArea->append(QString("%1 : is a Prime number").arg(result));
}
}
if(numberEntered == globalIndex){
timer->stop();
ui->resultArea->append(QString("End of count!!"));
}
globalIndex++;
}

Related

printf("%s",stringName) prints the wrong text but only once

I have a menu function, in which I input a question and two options, then the user choses one. It works just fine everytime but one ; I call
if (menu("ou est le corps?","interieur ","exterieur")==1)
{
but instead of printing "interieur " It shows "p?"
it works just fine without the space, but I need to make a space and \n does quite the same thing.
I have another call of this function, with \n which works fine so I have no idea about why this wouldn't work. Anyone has got an idea?
PS : the value of choix1 is then sent via bluetooth, and there it stays intact.
PPS : tell me if something is unclear, I'm not naturally english
PPPS(sorry) : tried to run the same code again, it seems to print a random character followed by "?", I had twice "p?", once "?" and once " '?"
[updates] once "#?"
int menu (String texte, String choix1, String choix2)
{
envoye = 0;
rxValue = "0";
while (digitalRead(M5_BUTTON_HOME) != LOW && rxValue == "0")
{
heure();
M5.Lcd.setTextSize(2);
M5.Lcd.print(texte);
M5.Lcd.printf("\n");
if (selec == 0)
{
M5.Lcd.printf("->%s %s", choix1, choix2);
}
else
{
M5.Lcd.printf(" %s ->%s", choix1, choix2);
}
if (M5.BtnB.read() != 0)
{
if (selec == 0)
{
selec = 1;
}
else
{
selec = 0;
}
while (M5.BtnB.read() != 0)
{
if(digitalRead(M5_BUTTON_HOME) == LOW)
{
M5.Lcd.fillScreen(BLACK);
delay(1000);
if(digitalRead(M5_BUTTON_HOME) == LOW)
{
choix=50;
heure();
delay(1000);
return 1;
}
}
}
}
if (deviceConnected && envoye == 0)
{
sendchoix(texte, choix1, choix2);
envoye++;
}
}
if (rxValue != "0")
{
recuble = &rxValue[0];
selec = atoi(recuble) - 1;
rxValue = "0";
}
M5.Lcd.fillScreen(BLACK);
delay(300);
return selec;
}
int menu (String texte, String choix1, String choix2) {
[...]
M5.Lcd.printf("->%s %s", choix1, choix2);
You cannot treat String objects as const char*, which is what the format specifier %s is expecting. String is an Arduino class for storing.. strings/character data, but an object of this class is not equivalent to the raw pointer to the data.
For that, you need to call the c_str() method on the String object to get the C-String pointer to the data, as shown in the documentation [1].
[..]
M5.Lcd.printf("->%s %s", choix1.c_str(), choix2.c_str());
[..]
[1] https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/c_str/

How to create a function in arduino?

I cannot get a function for this code to really work.
lastVal = val;
val = digitalRead(DT);
if (val == 1 && lastVal == 0)
{
if (digitalRead(CLK) == 1)
{
pos++;
}
else
{
pos--;
}
}
Can somebody pleas help me?
I am not sure if this is your entire code or not, but in case that is all of the code then I know the reason. Arduino requires the basic setup and loop functions to be referenced in the code, as long as it is referenced you should be fine - you can even leave the inside of the functions empty. You have not really asked the question very well so it is hard to see what you mean.
To create a function you can use this code:
void function_name_here(_parameters_here_)
{
//Code Here
}
To reference that function you just declare it by using:
function_name_here();
By the looks of it you might want to put your code in to the loop function, your code might look like this:
int DT = /* Value here */;
int pos = /* Value here */;
void setup()
{
pinMode(DT, INPUT);
}
void loop()
{
lastVal = val;
val = digitalRead(DT);
if (val == 1 && lastVal == 0)
{
if (digitalRead(CLK) == 1)
{
pos++;
}
else
{
pos--;
}
}
}

Display gif only once

I'm using gifs in my app. I'd like to only show my gif once and then make it disappear. But it keeps looping and showing again and again.
Here's what I've tried:
movie = new QMovie(":/in_game/src/countdown.gif");
processLabel = new QLabel();
this->addWidget(processLabel);
processLabel->setStyleSheet("background-color: rgba(0,0,0,0%)");
processLabel->setGeometry(280,250,128,128);
processLabel->setMovie(movie);
int i=0;
if(i<1)
{
movie->start();
i++;
}
else
{
movie->stop();
processLabel->setEnabled(false);
}
Of course in my .h I've created a QMovie and a QLabel... Any ideas on how to only display once ?
You have QMovie::frameCount() method and signal QMovie::frameChanged(). Check your current frame number and stop when current frame become equal QMovie::frameCount()
m_movie = new QMovie(":/gif/tenor.gif");
connect(m_movie, SIGNAL(frameChanged(int)),
this, SLOT(OnFrameChanged(int)));
ui->lblMovie->setMovie(m_movie);
m_movie->start();
And in slot:
void MainWindow::OnFrameChanged(int frame)
{
if (frame == m_movie->frameCount() - 1) {
m_movie->stop();
}
}

Pin:Insert two different instructions at the same address

I want to change the function inserted at the timing before the instruction with the same address.
What should I do?
For,example.
int count=10;
void insert_check_code(INS ins){
if(INS_Address(ins) == tmpaddr)
if(count > 5){
INS_InsertCall(ins,IPOINT_BEFORE,count--func)
}else {
INS_InsertCall(ins,IPOINT_BEFORE,count_printfunc)
}
}
In the above example,The count value returns to its original I want to change the function inserted at the timing before the instruction with the same address.
What should I do?
For,example.
int count=10;
void insert_check_code(INS ins){
if(INS_Address(ins) == tmpaddr)
if(count > 5){
INS_InsertCall(ins,IPOINT_BEFORE,count--func)
}else {
INS_InsertCall(ins,IPOINT_BEFORE,count_printfunc)
}
}
In the above example,The count value returns to its original value.
The target program is a simple server program, so we are using the fork () function.
Is it necessary to write a special description in Pintool for a program using the fork () function?value.
Move the if-else code into its own function and insert that function instead:
void conditional_func() {
if(count > 5){
count_decrement_func()
} else {
count_printfunc()
}
}
void insert_check_code(INS ins) {
INS_InsertCall(ins,IPOINT_BEFORE,conditional_func)
}
Regarding fork(), it depends on what behavior you want when fork()ing.
Keep in mind that if the application is multi-threaded, count access must be synchronized.

ImageView still visible after remove

I'm trying to program a network card game with javafx but I have a problem.
I have programmed an own class CardImageView that extends from ImageView so that I can save the Card-Object there.
I'm able to add this CardImageView to my main group on my pc and on my "enemy's" pc and I am able to remove it on my pc.
But when I try to remove it at my "enemy's" pc it is still visible (but not "interactable".
For network connectivity I am using a Task that gives me the commands as Strings over the message property.
private void onCardRemoved(String msg) {
System.out.println("CARD REMOVED BY: "+Thread.currentThread());
String[] params = msg.split(";");
//Calculating the coordinates of the card on screen
double x = getWidth() - (Double.parseDouble(params[1])/100*getWidth()+card_width/2);
double y = getHeight() - (Double.parseDouble(params[2])/100*getHeight()+card_height/2);
CardImageView toRemove = null;
System.out.println("To-Remove ("+x+"/"+y+")");
//searching for the card in my group
for(Node n : spielfeld.getChildren()) {
if(n instanceof CardImageView && n.getLayoutX() == x && n.getLayoutY() == y) {
toRemove = (CardImageView) n;
break;
}
}
//removing the card
if(toRemove != null) spielfeld.getChildren().remove(toRemove);
}

Resources