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. Modulus of difference of positive integer elements
Qt 6.11 is out! See what's new in the release blog

Modulus of difference of positive integer elements

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 850 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.
  • T Offline
    T Offline
    Troyer
    wrote on last edited by Troyer
    #1

    Hi!
    I'm making a table through a two dimensional array with random numbers and I can't implement the equation for my loop:
    Modulus of difference of positive integer elements.

    How can i do this?

    double my_rand(int accuracy) {
    
        double a = 0;
        a = (qrand() % int (qPow(10, accuracy) + 10000))/qPow(10, accuracy);
        return a;
    
    }
    
    
    void MainWindow::Mouse_Pressed_menu(){
        model = new QStandardItemModel(5, 2, this);
    
        ui->tableWidget->setRowCount(10);
        ui->tableWidget->setColumnCount(4);
    
        int count = 1;
        for (int i = 0; ui->tableWidget->rowCount(); i++) {
            for (int j = 0; j < ui->tableWidget->columnCount(); j++) {
    
                QTableWidgetItem *itm = new QTableWidgetItem(tr("%1").arg(my_rand(2)));
    
                ui->tableWidget->setItem(i, j, itm);
                count++;
    
            }
        }
    }
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      What are you asking ?

      • Modulus of difference of positive integer elements.
        Difference between ?
        Cols / rows ?
      T 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        What are you asking ?

        • Modulus of difference of positive integer elements.
          Difference between ?
          Cols / rows ?
        T Offline
        T Offline
        Troyer
        wrote on last edited by
        #3

        @mrjj
        A random value is output between rings / rows, and after that I need to find the difference module of all positive integers (so far I only have integers in the table) in the table and output, for example, in TextEdit

        image2.JPG

        mrjjM 1 Reply Last reply
        0
        • T Troyer

          @mrjj
          A random value is output between rings / rows, and after that I need to find the difference module of all positive integers (so far I only have integers in the table) in the table and output, for example, in TextEdit

          image2.JPG

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Troyer
          So diff between col 1 and col 2?
          and diff between col 3 and col 4 ? and so on ?

          T 1 Reply Last reply
          0
          • mrjjM mrjj

            @Troyer
            So diff between col 1 and col 2?
            and diff between col 3 and col 4 ? and so on ?

            T Offline
            T Offline
            Troyer
            wrote on last edited by
            #5

            @mrjj All at once)

            mrjjM 1 Reply Last reply
            0
            • T Troyer

              @mrjj All at once)

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Troyer
              between rows ?
              so sum of row 1 diff to sum of row 2 ?

              T 1 Reply Last reply
              0
              • mrjjM mrjj

                @Troyer
                between rows ?
                so sum of row 1 diff to sum of row 2 ?

                T Offline
                T Offline
                Troyer
                wrote on last edited by
                #7

                @mrjj Yes, that's it

                mrjjM 1 Reply Last reply
                0
                • T Troyer

                  @mrjj Yes, that's it

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Troyer
                  Hi
                  you can use the same loops to get the items.
                  you need a list to store the sums pr row.

                   for (int i = 0; ui->tableWidget->rowCount(); i++) {
                          for (int j = 0; j < ui->tableWidget->columnCount(); j++) {
                              QTableWidgetItem *itm = ui->tableWidget->item(i,j);
                             // sum the cols here
                          }
                   //   add sum to list
                  }
                  
                  then after you can loop the sum list and take diff.
                  
                  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