how to access widgets values?
by using folowing coding , i can able to create label,lineedit,pushbuttons.
how to access lineedit's typed value.. when the user clicks a pushbutton(EX show)?
i dont know how to get the values of WIDGETS.?
pls kindly help me
These are the files im using:
DynamicControls.h
Code:
//DynamicControls.h
class DynamicControls
: public QDialog{
Q_OBJECT
public:
DynamicControls
(QWidget *parent
= 0);
void createLayout();
//void getInfoLineEdit(QString LineEditName);
private slots:
void updateTable();
private:
};
DynamicControls.cpp
Code:
//DynamicControls.cpp
#include <QtGui>
#include <QSqlQuery>
#include <QVariant>
#include "dynamiccontrols.h"
DynamicControls
::DynamicControls(QWidget *parent
){
}
void DynamicControls
::createLabel(QString Wstr,
QString WTip,
int x,
int y
) {
label->setToolTip(WTip);
label->setObjectName(WTip);
layout->addWidget(label,x,y);
}
void DynamicControls
::createLineEdit(QString Wstr,
QString WTip,
int x,
int y
) {
lineEdit->setToolTip(WTip);
lineEdit->setObjectName(WTip);
layout->addWidget(lineEdit,x,y);
}
void DynamicControls
::createPushButton(QString Wstr,
QString WTip,
int x,
int y
) {
pushbutton->setToolTip(WTip);
pushbutton->setObjectName(WTip);
layout->addWidget(pushbutton,x,y);
}
void DynamicControls::createLayout()
{
setLayout(layout);
}
main.cpp
Code:
#include <QtGui/QApplication>
#include <QVariant>
#include <QLineEdit>
#include "dynamiccontrols.h"
#include "Connection.h"
int main(int argc, char *argv[])
{
DynamicControls *w = new DynamicControls;
w->createLabel("Id","IDLabel",0,0);
w->createLineEdit("","IDLineEdit",1,);
w->createLabel("Name","NameLabel",0,0);
w->createLineEdit("","NameLineEdit",1,);
w->createPushButton("Show","ShowButton",2,0);
w->createLayout();
w->show();
return a.exec();
}
in the above program, i want to get the values of lineedits namelinedit,idlineedit when the user click show button
Thnks
Thnks
Bala
Re: how to access widgets values?
Use the method text() for QLineEdit.
Also why are you doing the initializations in main.cpp and not in the class constructor??
Re: how to access widgets values?
With lineedit.text() I'm getting only the , latest lineedit's value.
but im using two lineedits.
how can i access both?
im using in main because,
i want to create dynamic line edits frm database
the folowing code will be replaced..
where q is the sqlquery with attributes for creating LINE EDIT.
OLD CODE:
w->createLineEdit("","NameLineEdit",1,1);
NEW CODE:
w->createLineEdit(q.value(1).toString(),q.value(1).t oString(),1,1);
HOW CAN I ACCESS ALL THE LINEEDITS VALUE?
bala
Re: how to access widgets values?
Quote:
Originally Posted by
BalaQT
HOW CAN I ACCESS ALL THE LINEEDITS VALUE?
Don't shout; it's rude.
Read something about C++ programming and how to store values and keep references.
Re: how to access widgets values?
Quote:
Originally Posted by
BalaQT
HOW CAN I ACCESS ALL THE LINEEDITS VALUE?
In class DynamicControls: give every line edit an id, and create a getter function ala return getLineDcit(id)->text();.