Good day all.
This post is an addon to a previous one where i had trouble creating the layout but not that is sorted. Here is my problem
I have a list of 3 items that i would like edited "They happen to corrispond to database field in mysql"
The amount of items can change so therefore i dont want to create the form statically then i would have to create 35 forms in stead of just 1 and pass the list to it.
So this is what i have got to create the form "Im not using a ui as it must be dynamic"
.h file
#ifndef FRM_MAINTENANCE_ALL_H
#define FRM_MAINTENANCE_ALL_H
#include <QWidget>
#include <QDialog>
#include <QtGui>
#include <QApplication>
#include <QDebug>
#include <QMessageBox>
#include <QList>
class frm_maintenance_all
: public QWidget{
Q_OBJECT
public:
explicit frm_maintenance_all
(QWidget *parent
= 0);
signals:
public slots:
private slots:
void frm_create
(QString tablename
);
void btn_process();
private:
};
#endif // FRM_MAINTENANCE_ALL_H
#ifndef FRM_MAINTENANCE_ALL_H
#define FRM_MAINTENANCE_ALL_H
#include <QWidget>
#include <QDialog>
#include <QtGui>
#include <QApplication>
#include <QDebug>
#include <QMessageBox>
#include <QList>
class frm_maintenance_all : public QWidget
{
Q_OBJECT
public:
explicit frm_maintenance_all(QWidget *parent = 0);
signals:
public slots:
private slots:
void frm_create(QString tablename);
void btn_process();
private:
};
#endif // FRM_MAINTENANCE_ALL_H
To copy to clipboard, switch view to plain text mode
.cpp file
#include "frm_maintenance_all.h"
frm_maintenance_all
::frm_maintenance_all(QWidget *parent
) :{
frm_create("test");
}
void frm_maintenance_all
::frm_create(QString tablename
) {
mylist<< "description" << "name" << "id";
int i;
for(i=1;i<=mylist.length();i++)
{
myline
->setText
("Text " + QString::number(i
));
//just setting text for testing myhoz->addWidget(myline);
}
myhoz->addWidget(btn_process_form);
setLayout(myhoz);
btn_process_form->setText(myline->text()); //it set the text to the last loop as expected but would like to be able to choose which box i want
connect(btn_process_form,SIGNAL(clicked()),this,SLOT(btn_process()));
setWindowTitle("Test");
show();
}
void frm_maintenance_all::btn_process()
{
//This does not work (expected to show line 3 option).
qDebug()<< myline->text();
//this function fails left uncomented here for reading
QLineEdit* mydyline
= parentWidget
()->findChild<QLineEdit
*>
("myline");
qDebug()<< mydyline->text();
// this also fails
QLineEdit* mydyline
= parent
()->findChild<QLineEdit
*>
("myline");
qDebug()<< mydyline->text();
// this also fails
QLineEdit* mydyline
= findChild<QLineEdit
*>
("myline");
qDebug()<< mydyline->text();
// this also fails
QLineEdit* mydyline
= this
->findChild<QLineEdit
*>
("myline");
qDebug()<< mydyline->text();
//FAILS WITH THIS ERROR
//The program has unexpectedly finished.
}
#include "frm_maintenance_all.h"
frm_maintenance_all::frm_maintenance_all(QWidget *parent) :
QWidget(parent)
{
frm_create("test");
}
void frm_maintenance_all::frm_create(QString tablename)
{
QVBoxLayout *myhoz = new QVBoxLayout;
QStringList mylist;
mylist<< "description" << "name" << "id";
int i;
QLineEdit *myline;
for(i=1;i<=mylist.length();i++)
{
myline = new QLineEdit;
myline->setText("Text " + QString::number(i)); //just setting text for testing
myhoz->addWidget(myline);
}
QPushButton *btn_process_form = new QPushButton;
myhoz->addWidget(btn_process_form);
setLayout(myhoz);
btn_process_form->setText(myline->text()); //it set the text to the last loop as expected but would like to be able to choose which box i want
connect(btn_process_form,SIGNAL(clicked()),this,SLOT(btn_process()));
setWindowTitle("Test");
show();
}
void frm_maintenance_all::btn_process()
{
//This does not work (expected to show line 3 option).
qDebug()<< myline->text();
//this function fails left uncomented here for reading
QLineEdit* mydyline = parentWidget()->findChild<QLineEdit*>("myline");
qDebug()<< mydyline->text();
// this also fails
QLineEdit* mydyline = parent()->findChild<QLineEdit*>("myline");
qDebug()<< mydyline->text();
// this also fails
QLineEdit* mydyline = findChild<QLineEdit*>("myline");
qDebug()<< mydyline->text();
// this also fails
QLineEdit* mydyline = this->findChild<QLineEdit*>("myline");
qDebug()<< mydyline->text();
//FAILS WITH THIS ERROR
//The program has unexpectedly finished.
}
To copy to clipboard, switch view to plain text mode
So there are 2 things i would like to please know :
1) How can i create a unique id or something for the LineEdit so i can reference it
eg so i could set the push button to line 2's text instead of the last one.
2) How do i then access the values From sub Functions
Help with this regard Will be awsome
Thanks very much
Bookmarks