⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 createdialog.cpp

📁 本代码采用嵌入式qt编写
💻 CPP
字号:
#include "createdialog.h"#include <qlabel.h>#include <qlineedit.h>#include <qmultilineedit.h>#include <qpushbutton.h>#include <qlayout.h>#include <qvariant.h>#include <qtooltip.h>#include <qwhatsthis.h>#include <qstring.h>#include <qmessagebox.h>#include <sqlite3.h>/*  *  Constructs a CreateDialog which is a child of 'parent', with the  *  name 'name' and widget flags set to 'f'  * *  The dialog will by default be modeless, unless you set 'modal' to *  TRUE to construct a modal dialog. */CreateDialog::CreateDialog( QWidget* parent,  const char* name, bool modal, WFlags fl )    : CreateDialogForm( parent, name, modal, fl ){    pDB = NULL;    errMsg = NULL;    int rc = sqlite3_open("test.db", &pDB );    connect( cancelButton, SIGNAL( clicked()), this, SLOT( close() ));    connect( okButton, SIGNAL( clicked()), this, SLOT( createTableSlot() ) );    }/*   *  Destroys the object and frees any allocated resources */CreateDialog::~CreateDialog(){    // no need to delete child widgets, Qt does it all for us}QString CreateDialog::getCreateCmd(){    int numLines = getMultiEditLines( fieldNameMultiEdit );    QString createCmd;    QString fieldNames;    for( int i = 0; i < numLines; i++ )    {	if( i != ( numLines - 1 )  ) {	    fieldNames += fieldNameMultiEdit -> textLine( i ) +",";	}	else {	    fieldNames += fieldNameMultiEdit -> textLine( i );	}    }        createCmd = "create table " + tableEdit -> text()  + "(" + fieldNames + ")" + ";";    return createCmd;	    }int CreateDialog::getMultiEditLines( QMultiLineEdit *multiEdit ){   int numLines = multiEdit -> numLines();   while( numLines > 0 && multiEdit -> textLine( numLines - 1 ) == "" )   {       numLines = numLines - 1;    }   return numLines;}void CreateDialog::insertIntoTableField(){    int rc = sqlite3_exec( pDB, "create table tableField( tableName, fieldName, property )", 0, 0, &errMsg );        int numLines = getMultiEditLines( fieldNameMultiEdit );    QString insertTableFieldCmd;   insertTableFieldCmd = "insert into tableField values('" 			  +  tableEdit -> text() + "','"	 			   +  tableEdit -> text() +"',1);";    rc = sqlite3_exec( pDB, insertTableFieldCmd, 0, 0, &errMsg );        for( int i = 0; i < numLines; i++ )    {	insertTableFieldCmd = "";		insertTableFieldCmd = "insert into tableField values('" 			      + tableEdit -> text() + "','" 			      + fieldNameMultiEdit -> textLine(i) + "',0)";	rc = sqlite3_exec( pDB, insertTableFieldCmd, 0, 0, &errMsg );    }}void CreateDialog::createTableSlot(){    int rc = sqlite3_exec(pDB, getCreateCmd(), 0, 0, &errMsg);    if( rc == SQLITE_OK ) {	insertIntoTableField();	QMessageBox::information(this, "Create Table", 				 "Create the table successful!" );	close();    }    else {	if( QMessageBox::warning( this, "Create Table",			      "Table " + tableEdit -> text()			      + " already exits\n"			      "Unable to create this table\n"			      "Do you still want to create another?", 			      QMessageBox::No, 			      QMessageBox::Yes) == QMessageBox::No)	    close();    }}void CreateDialog::closeEvent( QCloseEvent *event ){    int rc = sqlite3_close( pDB );    if( rc == SQLITE_OK ) {	event -> accept();    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -