Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Calculate clicks
Qt 6.11 is out! See what's new in the release blog

Calculate clicks

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Miikukka
    wrote on last edited by
    #1

    Hi!
    How I can programmer, that when I click pushbutton first time, listwidget says "Hello!" and when I click second time listwidget says "What's up?". Or first time: "Hello" and second time: listwidget clear empty itself.
    I've tried with int and char and everything. I've looked at the docs, but nothing. I don't still know that.

    I want, that when 5-10 lines are finished, next click will skip them.

    @void Words::on_pushButton_2_clicked()
    {
    int Time = 1;
    const char* S1 = "a dog";
    const char* S2 = "a cat";
    if (S1 == ui->lineEdit->text() && Time == 1)
    {
    ui->listWidget->addItem("RIGHT");
    Time = Time + 1;
    }
    if (S2 == ui->lineEdit->text() && Time == 2)
    {
    ui->listWidget->addItem("RIGHT");
    Time = Time + 1;
    }
    if ((!(S1 == ui->lineEdit->text()) && Time == 1) && !(S2 == ui->lineEdit->text() && Time == 2))
    {
    ui->listWidget->addItem("WRONG! Try again.");
    }
    }@

    Do you understand what I mean? Ask if you don't, I will explain.
    Thanks for answers!

    There are no stupid questions, only stupid answers.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vsorokin
      wrote on last edited by
      #2

      You have a lot of problems in your code.

      On first look, it should be something like:
      @void Words::on_pushButton_2_clicked()
      {
      static int Time = 1;
      QString S1 = "a dog";
      QString S2 = "a cat";

      if ((!(S1 == ui->lineEdit->text()) && Time == 1) && !(S2 == ui->lineEdit->text() && Time == 2))
      {
          ui->listWidget->addItem("WRONG! Try again.");
          return;
      }
      
      if (S1 == ui->lineEdit->text() && Time == 1)
      {
          ui->listWidget->addItem("RIGHT");
      }
      if (S2 == ui->lineEdit->text() && Time == 2)
      {
          ui->listWidget->addItem("RIGHT");
      }
      Time = Time + 1;
      

      }@

      --
      Vasiliy

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Miikukka
        wrote on last edited by
        #3

        Yes!
        Thank you very much!
        Fast and simple reply! I think "static" was the answer I looked for.
        Thanks! That helps me really much!

        There are no stupid questions, only stupid answers.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved