sorry for late
here is my code:
student.h
#ifndef STUDENT_H
#define STUDENT_H
#include <QWidget>
#include "ui_student.h"
class Student
: public QWidget ,
public Ui
::Student{
Q_OBJECT
public:
~Student();
bool opendb();
void view(int sh_d);
};
#endif
#ifndef STUDENT_H
#define STUDENT_H
#include <QWidget>
#include "ui_student.h"
class Student : public QWidget , public Ui::Student
{
Q_OBJECT
public:
Student(QWidget *parent = 0);
~Student();
bool opendb();
void view(int sh_d);
};
#endif
To copy to clipboard, switch view to plain text mode
studend.cpp
#include "student.h"
#include "ui_student.h"
#include <QSqlRecord>
#include <QSqlError>
extern int id;
Student
::Student(QWidget *parent
) :
{
setupUi(this);
createaction();
}
Student::~Student()
{
}
void Student::createaction()
{
connect(Sbutton,SIGNAL(clicked()),this,SLOT(searchstudent())) ;
}
void Student::searchstudent()
{
StudentSearch *s = new StudentSearch;
s->show();
}
void Student::viewinfo(int sh_d)
{
{
if(opendb())
{
query.setForwardOnly(true);
query.
exec(QString("{CALL information(%1)}").
arg(sh_d
));
if(!query.isActive())
{
query.lastError().text()+"Please Contact to Programer");
}
else
{
while(query.next())
{
rec = query.record();
N_label->setText(rec.value(0).toString());
F_label->setText(rec.value(1).toString());
C_label->setText(rec.value(2).toString());
M_label->setText(rec.value(3).toString());
D_label->setText(rec.value(4).toString());
SH_label->setText(rec.value(5).toString());
}
else
{
"can'nt open database");
}
}
}
}
}
bool Student::opendb()
{
db.setHostName("pishtazanedu.ir");
db.setDatabaseName("pop;DBQ=University.mdf");
db.setUserName("hamidarrb");
db.setPassword("ham!dArr_12973864");
if(!db.open())
return false;
return true;
}
#include "student.h"
#include "ui_student.h"
#include <QSqlRecord>
#include <QSqlError>
extern int id;
Student::Student(QWidget *parent) :
QWidget(parent)
{
setupUi(this);
createaction();
}
Student::~Student()
{
}
void Student::createaction()
{
connect(Sbutton,SIGNAL(clicked()),this,SLOT(searchstudent())) ;
}
void Student::searchstudent()
{
StudentSearch *s = new StudentSearch;
s->show();
}
void Student::viewinfo(int sh_d)
{
{
if(opendb())
{
QSqlQuery query(QSqlDatabase::database("con"));
QSqlRecord rec;
query.setForwardOnly(true);
query.exec(QString("{CALL information(%1)}").arg(sh_d));
if(!query.isActive())
{
QMessageBox::warning(this, tr("Error"),
query.lastError().text()+"Please Contact to Programer");
}
else
{
while(query.next())
{
rec = query.record();
N_label->setText(rec.value(0).toString());
F_label->setText(rec.value(1).toString());
C_label->setText(rec.value(2).toString());
M_label->setText(rec.value(3).toString());
D_label->setText(rec.value(4).toString());
SH_label->setText(rec.value(5).toString());
}
else
{
QMessageBox::critical(0, QObject::tr("Database Error"),
"can'nt open database");
}
}
}
}
}
bool Student::opendb()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC","con");
db.setHostName("pishtazanedu.ir");
db.setDatabaseName("pop;DBQ=University.mdf");
db.setUserName("hamidarrb");
db.setPassword("ham!dArr_12973864");
if(!db.open())
return false;
return true;
}
To copy to clipboard, switch view to plain text mode
StudentSearch.h
#ifndef STUDENTSEARCH_H
#define STUDENTSEARCH_H
#include <QWidget>
#include <QtGui>
#include "student.h"
#include "ui_studentsearch.h"
class StudentSearch
: public QWidget ,
public Ui
::StudentSearch{
Q_OBJECT
public:
StudentSearch
(QWidget *parent
= 0);
~StudentSearch();
void createaction();
private slots:
void search();
};
#endif
#ifndef STUDENTSEARCH_H
#define STUDENTSEARCH_H
#include <QWidget>
#include <QtGui>
#include "student.h"
#include "ui_studentsearch.h"
class StudentSearch : public QWidget , public Ui::StudentSearch
{
Q_OBJECT
public:
StudentSearch(QWidget *parent = 0);
~StudentSearch();
void createaction();
private slots:
void search();
};
#endif
To copy to clipboard, switch view to plain text mode
studentsearch.cpp
#include "studentsearch.h"
#include "student.h"
extern int id;
StudentSearch
::StudentSearch(QWidget *parent
)
{
setupUi(this);
createaction();
}
StudentSearch::~StudentSearch()
{
}
void StudentSearch::createaction()
{
connect(okbutton,SIGNAL(clicked()),this,SLOT(search()));
connect(cancelbutton,SIGNAL(clicked()),this,SLOT(close());
}
void StudentSearch::searchstudent()
{
id = addlineEdit->text().toInt();
Student *s = new Student;//my problem is here
s->viewinfo(id) //i call member viewinfo but student form do'nt show anything
// if i here i call s->show; it show anothe form and i can see
//the information of student
StudentSearch::close();
}
#include "studentsearch.h"
#include "student.h"
extern int id;
StudentSearch::StudentSearch(QWidget *parent)
:QWidget(parent)
{
setupUi(this);
createaction();
}
StudentSearch::~StudentSearch()
{
}
void StudentSearch::createaction()
{
connect(okbutton,SIGNAL(clicked()),this,SLOT(search()));
connect(cancelbutton,SIGNAL(clicked()),this,SLOT(close());
}
void StudentSearch::searchstudent()
{
id = addlineEdit->text().toInt();
Student *s = new Student;//my problem is here
s->viewinfo(id) //i call member viewinfo but student form do'nt show anything
// if i here i call s->show; it show anothe form and i can see
//the information of student
StudentSearch::close();
}
To copy to clipboard, switch view to plain text mode
Bookmarks