PDA

View Full Version : I cannot get the string from QLineEdit->text()!



MIH1406
3rd June 2010, 12:26
I have tried to get the text form QLineEdit but I always get "" empty string.

Here is my code:

Database.h


#ifndef DATABASE_H
#define DATABASE_H

#include <QObject>
#include <QtSql>
#include <QtGui>
#include "MainWindow.h"

class Database : public QObject {
Q_OBJECT

public:
Database(QObject *parent = 0);
~Database();

MainWindow *Gui;

private:
// Search Bar
void prepareList();
void updateListWidget();

// Records
void setupDatabase();
void setupModel();
void setupMapper();
void addMapping();
void doSave();


public:

private:
// Records
QSqlDatabase recordsDB;
QSqlQuery recordsQuery;
QSqlTableModel *recordsModel;
QDataWidgetMapper *recordsMapper;

// Search Bar SQL Related Members
QSqlDatabase searchDB;
QSqlQuery searchQuery;

QStringList namesList;
QStringList iqamasList;
QStringList passportsList;

QStringList tempNamesList;
QStringList tempIqamasList;
QStringList tempPassportsList;

// Misc.
enum CurrentStatus {Browsing, Adding, Editing};

private slots:
// Search Bar
void filterLists(QString currentNumber);
void resetForm();
void saveRecord();


};

#endif // DATABASE_H


See lines: 10, 18 & 23

Part of (Database.cpp)


Database::Database(QObject *parent) : QObject(parent) {
// The GUI
Gui = new MainWindow;
Gui->show();

// Records
setupDatabase();
setupModel();
setupMapper();
//saveRecord(); from here I get the text normally.

// Search Bar
prepareList();

// Search Button Connection
connect(Gui->ui->leSearch, SIGNAL(textChanged(QString)), this, SLOT(filterLists(QString)));
connect(Gui->ui->actionNew, SIGNAL(triggered()), this, SLOT(resetForm()));
connect(Gui->ui->actionSave, SIGNAL(triggered()), this, SLOT(saveRecord())); // from here I cannot get the text, I just get empty string "".
} // Database(QObject *parent = 0)

// Slot
void Database::saveRecord() {
// if i call this slot through a connection "connect() see line 18" all these QLineEdits return empty string but actually the are filled with information.
QString voucherTypeEst = QString(Gui->ui->radioEst->isChecked());
QString voucherTypeCo = QString(Gui->ui->radioCo->isChecked());
QString voucherTypeGov = QString(Gui->ui->radioGov->isChecked());
QString firstARName = Gui->ui->leARFirstName->text();
QString firstENName = Gui->ui->leENFirstName->text();
QString iqamaNumber = Gui->ui->leIqamaNumber->text();
QString nationality = Gui->ui->leNationality->text();
QString job = Gui->ui->leJob->text();
QString religion = Gui->ui->leReligion->text();
QString passportNumber = Gui->ui->lePassportNumber->text();
QString issuePlace = Gui->ui->leIssuePlace->text();
QString entranceNumber = Gui->ui->leEntryNumber->text();
QString entrancePort = Gui->ui->leEntryPort->text();
QString iqamaDate = Gui->ui->leIqamaExpiryDate->text();
QString birthdayDate = Gui->ui->leBirthdayDate->text();
QString passportIssueDate = Gui->ui->lePassportIssueDate->text();
QString passportExpiryDate = Gui->ui->lePassportExpiryDate->text();
QString entryDate = Gui->ui->leEntryDate->text();
QString voucherTypeSng = QString(Gui->ui->radioSng->isChecked());
QString voucherName = Gui->ui->leCurrentVoucherName->text();
QString voucherNumber = Gui->ui->leCurrentVoucherNumber->text();
QString voucherAddress = Gui->ui->leCurrentVoucherAddress->text();
QString voucherPhone = Gui->ui->leCurrentVoucherPhone->text();
QString fatherARName = Gui->ui->leARFatherName->text();
QString grandARName = Gui->ui->leARGrandName->text();
QString familyARName = Gui->ui->leARFamilyName->text();
QString fatherENName = Gui->ui->leENFatherName->text();
QString grandENName = Gui->ui->leENGrandName->text();
QString familyENName = Gui->ui->leENFamilyName->text();
}