well, I have read some tens of times most tutorials,posts and examples. I think I have understood most of the functions and classes, but I fail to put all these together.
I am looking for a very simple example:
a tableview with just 1 row and 2 columns, just two boxes.
One box should be a widget-qcombobox and the other just normal box to insert a string.
Now, I want to connect the database of the tableview with a QLineEdit (let's call it resultLineEdit) every time a new value is inserted by the user.
Can you give me a piece of code to start with?
Added after 1 58 minutes:
i started like this:
{
Q_OBJECT
public:
private:
};
class M : public QWidget
{
Q_OBJECT
public:
M(QWidget *parent = 0);
private:
QStandardItemModel *model;
QTableView *table;
QLineEdit * resultEdit;
QPushButton *quit;
};
To copy to clipboard, switch view to plain text mode
{
int r = 2,c = 2;
table->setModel(model);
for (int row = 0; row < r; ++row) {
for (int column = 0; column < c; ++column) {
model->setItem(row,column,item);
}
}
resultEdit->setText("results here....");
quit->setText("quit!");
connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
mainLayout->addWidget(resultEdit);
mainLayout->addWidget(quit);
mainLayout->addWidget(table);
setLayout(mainLayout);
}
M::M(QWidget *parent)
: QWidget(parent)
{
int r = 2,c = 2;
model = new QStandardItemModel(r,c);
table = new QTableView();
table->setModel(model);
for (int row = 0; row < r; ++row) {
for (int column = 0; column < c; ++column) {
QStandardItem *item = new QStandardItem(QString("iii"));
model->setItem(row,column,item);
}
}
resultEdit = new QLineEdit;
resultEdit->setText("results here....");
quit = new QPushButton;
quit->setText("quit!");
connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->addWidget(resultEdit);
mainLayout->addWidget(quit);
mainLayout->addWidget(table);
setLayout(mainLayout);
}
To copy to clipboard, switch view to plain text mode
the question is:
how can I connect the the changes of any item of the table to the slot setText(QString) of the resultEdit?
Bookmarks