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



  • 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



  • 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) {
    ...
    }
    }
    @



  • 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



  • [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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.