I'm having troubles with the code here:
inputmatrix.h:
#ifndef INPUTMATRIX_H
#define INPUTMATRIX_H
#include <QPushButton>
#include <QObject>
#include <QSignalMapper>
{
Q_OBJECT
private:
int nrow;
int ncol;
public:
InputMatrix();
InputMatrix(int nrow, int ncol);
~InputMatrix();
public slots:
};
#endif // INPUTMATRIX_H
#ifndef INPUTMATRIX_H
#define INPUTMATRIX_H
#include <QPushButton>
#include <QObject>
#include <QSignalMapper>
class InputMatrix : QObject
{
Q_OBJECT
private:
QPushButton ** p;
int nrow;
int ncol;
QSignalMapper *signalMapper;
public:
InputMatrix();
InputMatrix(int nrow, int ncol);
~InputMatrix();
void Show(QWidget*);
QPushButton GetItem(int i,int j);
public slots:
void SetItem(const QString &ID);
};
#endif // INPUTMATRIX_H
To copy to clipboard, switch view to plain text mode
inputmatrix.cpp:
#include "inputmatrix.h"
#include <QPushButton>
#include "mainwindow.h"
#include <QSignalMapper>
#include <QString>
#include <QMessageBox>
#include <QChar>
InputMatrix::InputMatrix()
{}
InputMatrix::InputMatrix(int nr, int nc)
{
ncol=nc;
nrow = nr;
for (int i=0; i<nrow; i++)
}
void InputMatrix
::Show(QWidget *obj
) {
int alt = (obj->height()-100)/nrow;
const QString ID
= "ij";
// this will identify the buttons in the PushButton matrix for (int i=0; i<nrow; i++)
{
ID.insert(0,(Qchar) i); // FIRST ERROR
for (int j=0; j<ncol; j++)
{
ID.
insert(1,
(QChar) j
);
// SECOND ERROR p[i][j].setParent(obj); // obj = window on which I'll show the matrix
p[i][j].setGeometry(50+(j*alt), 70 +(i*alt),alt, alt);
connect(&p[i][j], SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping(&p[i][j], ID);
p[i][j].show();
}
}
connect(signalMapper,
SIGNAL(mapped
(const QString &)),
this,
SLOT(SetItem
(const QString &)));
}
void InputMatrix
::SetItem(const QString & ID
) {
aux.append(ID);
msg.setText(aux);
msg.exec();
}
{
//return p[i][j];
}
InputMatrix::~InputMatrix()
{
for (int i=0; i<nrow; i++)
delete [] p[i];
delete p;
}
#include "inputmatrix.h"
#include <QPushButton>
#include "mainwindow.h"
#include <QSignalMapper>
#include <QString>
#include <QMessageBox>
#include <QChar>
InputMatrix::InputMatrix()
{}
InputMatrix::InputMatrix(int nr, int nc)
{
ncol=nc;
nrow = nr;
p = new QPushButton*[nrow];
for (int i=0; i<nrow; i++)
p[i] = new QPushButton[ncol];
}
void InputMatrix::Show(QWidget *obj)
{
int alt = (obj->height()-100)/nrow;
signalMapper= new QSignalMapper(this);
const QString ID = "ij"; // this will identify the buttons in the PushButton matrix
for (int i=0; i<nrow; i++)
{
ID.insert(0,(Qchar) i); // FIRST ERROR
for (int j=0; j<ncol; j++)
{
ID.insert(1,(QChar) j); // SECOND ERROR
p[i][j].setParent(obj); // obj = window on which I'll show the matrix
p[i][j].setGeometry(50+(j*alt), 70 +(i*alt),alt, alt);
connect(&p[i][j], SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping(&p[i][j], ID);
p[i][j].show();
}
}
connect(signalMapper, SIGNAL(mapped(const QString &)),
this, SLOT(SetItem(const QString &)));
}
void InputMatrix::SetItem(const QString & ID)
{
QMessageBox msg;
QString aux = "You have pressed ";
aux.append(ID);
msg.setText(aux);
msg.exec();
}
QPushButton InputMatrix::GetItem(int i,int j)
{
//return p[i][j];
}
InputMatrix::~InputMatrix()
{
for (int i=0; i<nrow; i++)
delete [] p[i];
delete p;
}
To copy to clipboard, switch view to plain text mode
the error is the same at both of the rows I commented in the code. It is:
passing 'const QString' as 'this' argument of 'QString& QString::insert(int, QChar)' discards qualifier
why I'm wrong?
Bookmarks