Qt-interest Archive, January 2007
QComboBox and QDataWidgetMapper
Message 1 in thread
hi.
i'm trying to map a QComboBox with QDataWidgetMapper, but don't get results as
expected.
the sources are attached.
is it my fault or a bug?
thanks in advance,
alexander
#include "cb_vs_dwm.hpp"
#include "cb_vs_dwm.hpp"
MyWindow::MyWindow():QMainWindow()
{
// setup combobox
this->cb = new QComboBox(this);
this->cb->addItem("a bla", QVariant("a"));
this->cb->addItem("b bla", QVariant("b"));
this->cb->addItem("b bla", QVariant("c"));
this->cb->addItem("d bla", QVariant("d"));
this->cb->addItem("e bla", QVariant("e"));
// setup model
this->model = new QStandardItemModel(1, 1, this);
// setup datawidgetmapper
this->dwm = new QDataWidgetMapper(this);
this->dwm->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
this->dwm->setModel(this->model);
this->dwm->addMapping(this->cb, 0);
// connect signals
this->connect(this->cb,
SIGNAL(currentIndexChanged(int)),
this, SLOT(cbChanged(int)));
this->connect(this->dwm,
SIGNAL(currentIndexChanged(int)),
this, SLOT(dwmChanged(int)));
// reset datawidgetmapper
this->dwm->toFirst();
}
void MyWindow::cbChanged(int i)
{
QModelIndex mi = this->model->index(0, 0);
QString data = mi.data().toString();
qDebug() <<"cbChanged, data: "<<data<<", i: "<<i;
}
void MyWindow::dwmChanged(int i)
{
QModelIndex mi = this->model->index(0, 0);
QString data = mi.data().toString();
qDebug() <<"dwmChanged, data: "<<data<<", i: "<<i;
}
#include <QObject>
#include <QObject>
#include <QMainWindow>
#include <QComboBox>
#include <QStandardItemModel>
#include <QDataWidgetMapper>
#include <QApplication>
#include <QModelIndex>
#include <QtDebug>
class MyWindow: public QMainWindow
{
Q_OBJECT
public:
MyWindow();
protected slots:
void cbChanged(int i);
void dwmChanged(int i);
private:
QComboBox *cb;
QStandardItemModel *model;
QDataWidgetMapper *dwm;
};
#include "cb_vs_dwm.hpp"
#include "cb_vs_dwm.hpp"
int main(int argc, char *argv[])
{
//Q_INIT_RESOURCE(application);
QApplication app(argc, argv);
MyWindow w;
w.show();
return app.exec();
}
Message 2 in thread
> i'm trying to map a QComboBox with QDataWidgetMapper, but don't get
> results as
> expected.
What results are you expecting? What results are you getting?
--Justin
--
[ signature omitted ]
Message 3 in thread
justin@xxxxxxx wrote:
>> i'm trying to map a QComboBox with QDataWidgetMapper, but don't get
>> results as
>> expected.
>
> What results are you expecting? What results are you getting?
i expect the selection of the combobox changes the model to the attached
QVariant. this works fine with other widgets, but i can't get the combobox to be
mapped.
seems to me, that the model isn't changed in any way by the mapper.
alexander
--
[ signature omitted ]