www.pudn.com > qt_mysql.zip > MyConnDlg.cpp


// MyConnDlg.cpp: implementation of the MyConnDlg class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "MyConnDlg.h" 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
MyConnDlg::MyConnDlg(QWidget * parent, const char * name) 
{ 
	this->setCaption("MyQuery"); 
	setMaximumSize( 300, 180 ); 
	QVBox* vbox=new QVBox(this); 
	vbox->setGeometry(60,30,200,120); 
	QHBox* hbox1=new QHBox(vbox);		//第一行 
	QHBox* hbox2=new QHBox(vbox);		//第二行 
	QHBox* hbox3=new QHBox(vbox);		//第三行 
	QHBox* hbox4=new QHBox(vbox);		//第四行 
 
	QLabel* labserver=new QLabel("Server Name",hbox1); 
	m_editserver=new QLineEdit(hbox1); 
	 
	QLabel* labuser=new QLabel("  User Name",hbox2); 
	m_edituser=new QLineEdit(hbox2); 
	 
	QLabel* labpwd=new QLabel("   PassWord",hbox3); 
	m_editpwd=new QLineEdit(hbox3); 
	m_editpwd->setEchoMode(QLineEdit::Password); 
 
	QPushButton* butok=new QPushButton("OK",hbox4); 
	//butok->setDefault(true); 
	connect(butok,SIGNAL(clicked()),this,SLOT(OnOk())); 
 
	QPushButton* butcancel=new QPushButton("Cancel",hbox4); 
	connect(butcancel,SIGNAL(clicked()),this,SLOT(OnCancel())); 
	 
 
} 
 
MyConnDlg::~MyConnDlg() 
{ 
 
} 
 
void MyConnDlg::OnOk() 
{ 
	assert(m_connsql); 
	QString user,host,pwd; 
	host=m_editserver->text(); 
	user=m_edituser->text(); 
	pwd=m_editpwd->text(); 
	if (!mysql_real_connect(m_connsql,host,user,pwd,NULL,0,NULL,0)){ 
		QMessageBox::warning(this,"Connect Error",(QString)mysql_error(m_connsql)); 
	}else{ 
		accept(); 
	}; 
} 
 
void MyConnDlg::OnCancel() 
{ 
	reject(); 
} 
 
void MyConnDlg::setMySQL(MYSQL *mysql) 
{ 
	m_connsql=mysql; 
}