Thanks for your attention wysota. This what i have tried to do so far:
x
::x(QWidget *parent, Qt
::WFlags flags
){
setupUi(this);
model->setTable("user_info");
mapper->setModel(model);
mapper->addMapping(spinBox, 0);
mapper->addMapping(lineEdit, 1);
mapper->addMapping(lineEdit_2, 2);
mapper->addMapping(spinBox_2, 3);
mapper->toFirst();
x::x(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
setupUi(this);
QSqlTableModel *model = new QSqlTableModel(this);
model->setTable("user_info");
QDataWidgetMapper *mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->addMapping(spinBox, 0);
mapper->addMapping(lineEdit, 1);
mapper->addMapping(lineEdit_2, 2);
mapper->addMapping(spinBox_2, 3);
mapper->toFirst();
To copy to clipboard, switch view to plain text mode
Class "x" inherits a form that i created. This form was created in designer with the editors (lineEdit, lineEdit_2,ect) that were mapped to "mapper".
The code above is the constructor for class "x". Below is the declaration for class "x".
#ifndef X_H
#define X_H
#include <QtGui/QMainWindow>
#include "ui_x.h"
{
Q_OBJECT
public:
x
(QWidget *parent
= 0, Qt
::WFlags flags
= 0);
~x();
};
#ifndef X_H
#define X_H
#include <QtGui/QMainWindow>
#include "ui_x.h"
class x : public QMainWindow,public Ui_xClass
{
Q_OBJECT
public:
x(QWidget *parent = 0, Qt::WFlags flags = 0);
~x();
};
To copy to clipboard, switch view to plain text mode
This was simply an attempt to get QDatawidgetmapper to work as explained in the docs, but i would really like to use it in my project.
my connections to the database were done in main, and works fine as i tested it by assigning the model to a QTableView, and the information came up. Nothing comes up in the widgets that were mapped though.
Bookmarks