C++ (Qt)void MainWindow::ShowDatabases(){ QSqlDatabase db; QSqlQuery q; db = QSqlDatabase::addDatabase("QMYSQL"); db.setDatabaseName( "organization" ); db.setHostName("localhost"); db.setUserName("root"); db.setPassword("************"); if(db.open()) { QMessageBox hello; QString s; hello.setText("Connected!"); q.exec("show databases"); while(q.next()) { s+=q.value(0).toString()+"\n"; } ui->textEdit->setText(s); } else { QMessageBox hello; hello.setText("Not Connected!"); hello.exec(); } }
Bashmysql -u root -p ***
qDebug ()<<QSqlDatabase::drivers ();
SQLmysql> SHOW DATABASES;+--------------------+| DATABASE |+--------------------+| information_schema || mysql || organization |+--------------------+3 rows IN SET (0.22 sec)
""