
Originally Posted by
wysota
Is your application multithreaded?
No it is not
Here is an example:
test.h
#ifndef TEST_H_
#define TEST_H_
#include "types.h"
#include "Ui_test.h"
class tableView
: public QDialog,
protected Ui_Dialog
{
Q_OBJECT
public:
tableView
(QWidget* parent
= 0, Qt
::WindowFlags flags
= 0);
private slots:
void btn_testClick();
};
#endif // end of #ifndef TEST_H_
#ifndef TEST_H_
#define TEST_H_
#include "types.h"
#include "Ui_test.h"
class tableView : public QDialog, protected Ui_Dialog
{
Q_OBJECT
public:
tableView(QWidget* parent = 0, Qt::WindowFlags flags = 0);
private slots:
void btn_testClick();
};
#endif // end of #ifndef TEST_H_
To copy to clipboard, switch view to plain text mode
test.cpp
#include <QtGui/QMessageBox>
#include <QtGui/QStandardItemModel>
#include <QtGui/QItemSelectionModel>
#include "test.h"
tableView
::tableView(QWidget* parent
/* = 0 */, Qt
::WindowFlags flags
/* = 0 */){
// create gui elements defined in the Ui_tableView class
setupUi(this);
connect(btn_test, SIGNAL(clicked()), this, SLOT(btn_testClick()) );
setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint);
if (!tv_test->model())
{
tv_test->setModel(newModel);
}
for (int idx = 1; idx < 11; idx++)
{
model->appendRow( item1 );
}
}
void tableView::btn_testClick()
{
if (model)
{
QModelIndexList selectedRows = model->selectedRows();
}
}
#include <QtGui/QMessageBox>
#include <QtGui/QStandardItemModel>
#include <QtGui/QItemSelectionModel>
#include "test.h"
tableView::tableView(QWidget* parent /* = 0 */, Qt::WindowFlags flags /* = 0 */)
: QDialog(parent, flags)
{
// create gui elements defined in the Ui_tableView class
setupUi(this);
connect(btn_test, SIGNAL(clicked()), this, SLOT(btn_testClick()) );
setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint);
if (!tv_test->model())
{
QStandardItemModel *newModel = new QStandardItemModel(0, 1);
tv_test->setModel(newModel);
}
QStandardItemModel *model = dynamic_cast<QStandardItemModel*>( tv_test->model() );
for (int idx = 1; idx < 11; idx++)
{
QStandardItem* item1 = new QStandardItem( QString("bla_%1").arg(idx) );
model->appendRow( item1 );
}
tv_test->setSelectionModel( new QItemSelectionModel( model ) );
}
void tableView::btn_testClick()
{
QItemSelectionModel *model = tv_test->selectionModel();
if (model)
{
QModelIndexList selectedRows = model->selectedRows();
}
}
To copy to clipboard, switch view to plain text mode
Remark: The code just crashes if I select a row and push the Test button.
Bookmarks