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. QList is still empty
Qt 6.11 is out! See what's new in the release blog

QList is still empty

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.5k 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.
  • S Offline
    S Offline
    Sibyx
    wrote on last edited by
    #1

    Hi! I have Qlist<double> where I wanna add some items and after I want read this data from it. I have loop where I'm adding some data using function append, but my QList is still empty! Here's my code:
    @
    int x, y;
    //...
    if (gData.columnsX.count() == 1) {
    QList<double> udajeX;
    for (x = gData.lineRange.from, y=1; x <= gData.lineRange.to; x++, y++) {
    if (provider->getColumnType(gData.columnsX.at(0).name) != "real") {
    udajeX.append(y);
    udajeX.insert(y-1, (double)y);
    //qDebug() << (double)y;
    }
    else {
    udajeX.append(provider->model->record(x-1).value(gData.columnsX.at(0).name).toDouble());
    qDebug() << provider->model->record(x-1).value(gData.columnsX.at(0).name).toDouble();
    }
    }
    qSort(udajeX);
    QPointF pFrom, pTo;
    for (x = gData.lineRange.from; x <= gData.lineRange.to; x++) {
    for (y = 1; y < gData.columnsY.count(); y++) {
    pFrom.setX(udajeX.at(x-1) * gData.columnsX.at(0).max / 400);
    pFrom.setY(provider->model->record(x-1).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300);
    pTo.setX(udajeX.at(x) * gData.columnsX.at(0).max / 400);
    pTo.setY(provider->model->record(x).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300);
    qDebug() << udajeX.at(x); //nothing!
    //qDebug() << "X:" << udajeX.at(x-1) * gData.columnsX.at(0).max / 400 << "Y:" << provider->model->record(x-1).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300;
    //qDebug() << "X:" << udajeX.at(x) * gData.columnsX.at(0).max / 400 << "Y:" << provider->model->record(x).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300;
    //qDebug() << "---------------------------------------";
    //qDebug() << "From " << x-1 << " to " << x;
    painter->drawLine(pFrom, pTo);
    }
    }
    //qDebug() << provider->getColumnType(gData.columnsX.at(0).name);
    }
    @

    It can be stupid problem but I'm tired and i can't found any mistake :) Thanks!

    [EDIT: reformatted code, Volker]

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      You should check if there is something in the udajeX around your qSort().

      @
      int x, y;
      ...
      if (gData.columnsX.count() == 1) {
      QList<double> udajeX;
      for (x = gData.lineRange.from, y=1; x <= gData.lineRange.to; x++, y++) {
      if (provider->getColumnType(gData.columnsX.at(0).name) != "real") {
      udajeX.append(y);
      udajeX.insert(y-1, (double)y);
      //qDebug() << (double)y;
      }
      else {
      udajeX.append(provider->model->record(x-1).value(gData.columnsX.at(0).name).toDouble());
      qDebug() << provider->model->record(x-1).value(gData.columnsX.at(0).name).toDouble();
      }
      }
      qDebug() << udajeX.size(); // <<<<<<<<<<<<<<<<<<<<<<<
      qSort(udajeX);
      qDebug() << udajeX.size(); // <<<<<<<<<<<<<<<<<<<<<<<<
      QPointF pFrom, pTo;
      for (x = gData.lineRange.from; x <= gData.lineRange.to; x++) {
      qDebug() << "gData.columnsY.count() " << gData.columnsY.count(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
      for (y = 1; y < gData.columnsY.count(); y++) {
      pFrom.setX(udajeX.at(x-1) * gData.columnsX.at(0).max / 400);
      pFrom.setY(provider->model->record(x-1).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300);
      pTo.setX(udajeX.at(x) * gData.columnsX.at(0).max / 400);
      pTo.setY(provider->model->record(x).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300);
      qDebug() << udajeX.at(x); //nothing!
      //qDebug() << "X:" << udajeX.at(x-1) * gData.columnsX.at(0).max / 400 << "Y:" << provider->model->record(x-1).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300;
      //qDebug() << "X:" << udajeX.at(x) * gData.columnsX.at(0).max / 400 << "Y:" << provider->model->record(x).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300;
      //qDebug() << "---------------------------------------";
      //qDebug() << "From " << x-1 << " to " << x;
      painter->drawLine(pFrom, pTo);
      }
      }
      //qDebug() << provider->getColumnType(gData.columnsX.at(0).name);
      }
      }
      @
      This is brain to keyboard source, but see, if it gives something meaningful.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sibyx
        wrote on last edited by
        #3

        No change in size... I've tried this before

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          Does your program do the loop?
          Furthermore, I am not sure since you are putting an int to QList<double> . I think it should not be a problem, but change it to
          @
          udajeX.append( double ( y ));
          udajeX.insert(y-1, (double)y);
          @
          In addition that looks a little strange from the logic, but I assume that is because of your efforts to find the problem.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sibyx
            wrote on last edited by
            #5

            I'm sorry for chaotic code but I'm looking for mistake a long time and some parts and lines of code are strange. I tried convert y from int to double before, but without any effect. And I have mistake in my previous post. In code is line with insert commented.
            @udajeX.append(double (y));
            //udajeX.insert(y-1,(double)y);
            @

            1 Reply Last reply
            0
            • K Offline
              K Offline
              koahnig
              wrote on last edited by
              #6

              Did you use the debugger and checked that the program loops there ?
              If it does not put anything in there, no wonder ....

              Vote the answer(s) that helped you to solve your issue(s)

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                Is your first loop actually executed?

                At the end of each loop iteration, check if something was added to the list.
                Add

                @
                qDebug() << udajeX;
                @

                to see what's in the list.

                PS:
                Please remove leading whitespace from code snippets before posting, otherwise it makes lines wrap and reading hard. You're likely to disattract possibles helpers :-)

                http://www.catb.org/~esr/faqs/smart-questions.html

                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