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. Creating array / list of labels (As argument of a matrix)

Creating array / list of labels (As argument of a matrix)

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.4k Views
  • 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
    TommoUK
    wrote on last edited by
    #1

    I have managed to put my labels into a list now, which i can then change via labels.at(5).SetText for example..

    @ int* input_data = new int[MN];
    while (numberOfLabels<=M
    N)
    {
    for (int f2=0; f2<N; f2++)
    {
    //QLabel *labels = new QLabel;
    labels << new QLabel(this);
    ui->The_Grid->addWidget(labels.at(Index), row, f2);
    numberOfLabels++;

             if (numberOfLabels>M*N)
             {
                 break;
             }
    
                if (input_data[Index] == 1)
                {
                    labels.at(Index)->setAutoFillBackground( true );
                    palette.setColor(QPalette::Background,Qt::green);
                    labels.at(Index)->setPalette(palette);
                   // labels->setText(QString::number(1));
                }
                if (input_data[Index] == 0)
                {
                    labels.at(Index)->setAutoFillBackground( true );
                    palette.setColor(QPalette::Background,Qt::black);
                    labels.at(Index)->setPalette(palette);
                    //labels->setText(QString::number(0));
                }
                if (input_data[Index] == 5)
                {
                    //QMessageBox::information(this,"this","input_data = 5");
                    labels.at(Index)->setAutoFillBackground( true );
                    palette.setColor(QPalette::Background,Qt::blue);
                    labels.at(Index)->setPalette(palette);
                    //labels->setText("Start");
                }
                if (input_data[Index] == 6)
                {
                    labels.at(Index)->setAutoFillBackground( true );
                    palette.setColor(QPalette::Background,Qt::red);
                    labels.at(Index)->setPalette(palette);
                    //labels->setText("End");
                }
    
                Index++;
    
              }
            row++;
        }
    
    Matrix NewMatrix(M,N,input_data);
    

    @

    I am still however getting an error "LNK2019" when trying to create my Matrix object..

    My header looks like this

    @#ifndef MATRIX_H
    #define MATRIX_H

    class Matrix
    {
    protected:
    int M;
    int N;
    int* data;

    public:
    Matrix(int sizeR, int sizeC, int* input_data); //Default Constructor
    }@

    And my actual .cpp for matrix looks like this

    @#include "matrix.h"

    Matrix::Matrix(int sizeR, int sizeC, int* input_data)
    {
    //cout<<"\n !!! NEW MATRIX !! Constructor Called";
    M = sizeR; //Row
    N = sizeC; // Column
    //int* data = new int[MN];
    //int
    data;

    // Deep copy contents of input_data
    for (int ii=0; ii<M*N; ii++)
    {
       data[ii] = input_data[ii];
    }
    

    }@

    Any advice / examples with the code I have so far would be appreciated!

    Heres a link to screenshot of program output
    http://imgur.com/ocUA3ZI

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      I assume that you have initialized row, Index, and numberOfLabels before the loop. I don't see anything wrong with the line
      @
      ui->The_Grid->addWidget(labels, row, f2);
      @
      Could you give exact error message that it produces.

      Assuming that input_data is one-dimensional array of size MN then Index = row * N + col, I would change code to something like
      @
      for (int row = 0; row < M; ++row) {
      for (int col = 0; col < N; ++col) {
      QLabel
      label = new QLabel;
      ui->The_Grid->addWidget(label, row, col);
      ...
      if (input_data[row * N + col] == 1) {
      ...
      }
      }
      @

      1 Reply Last reply
      0
      • T Offline
        T Offline
        TommoUK
        wrote on last edited by
        #3

        Thanks for the response, I have now managed to put them into a list, the results are impressive. Qt handles 600 + labels surprisingly well.

        I am however having still having problems with my Matrix class, please read original post I have edited

        Thanks, Tom

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          [quote author="TommoUK" date="1397016703"]I am still however getting an error “LNK2019” when trying to create my Matrix object.[/quote]

          Error LNK2019 "means":http://msdn.microsoft.com/en-us/library/799kze2z.aspx
          @
          unresolved external symbol 'symbol' referenced in function 'function'
          @

          The symbol and the function names are in an error log, which is available in console if you build from a console or in "Compile Output" tab at the bottom of the screen if you use QtCreator then you can find full error log

          You can open it by Alt+4.

          PS: It is better to add another post in the thread instead of editing the original post. Other people will not be able to follow the conversation if the original thread is modified.

          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