C++ Qt 51 - Intro to Databases with Qt

VoidRealms · 177K views · 2011 · 10:12

Open on YouTube

C, C++, Rust, Go & systems languagesDatabases & storagetutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering Qt database questions and recommend it as a clear starting point for SQL connections and models.

Recommended by 2 people across 2 different months, 2011 to 2015.

What it is

A 10-minute beginner tutorial from VoidRealms, part of a long C++ Qt series, introducing how to work with databases in Qt using the QtSql module. It walks through the basic setup and code needed to open a database connection from a Qt application.

What people said

Recommends Exa · 2011-06 · Stack Overflow · on “Qt - Database programming”

See Qt Database Docs [LINK] Qt Sql Programming [LINK] (as suggested by Christian Rau) This example [LINK] Qt video #51 on YouTube [this video] and following

Recommends Armando · 2015-04 · Stack Overflow · on “SQL connections in several threads in a Qt application”

Follow this [this video] tutorial from VoidRealms @ youtube. He has a very good explanation on sql connection,models and many other stuff about Qt. If you still need more help after watching it, it would be my pleasure to send you a sample code for you to test it.

Cites Jan Hettenkofer · 2014-02 · Stack Overflow · on “Trying to connect to Postgres with Qt”

Currently I am working on a learning by doing project that should use a database to save the data. I am using Qt C++ and I have installed postgres.app. My first attempt to write a connection method is mainly taken from this source ( [this video] ) and looks like this after some modifications: int database::connect(QString servername, QString dbname){ QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL"); db.setConnectOptions(); QString dsn = QString("Driver={PostgreSQL};Server=%1;Port=5432;Database=%2;").arg(servername).arg(dbname); db.setDatabaseName(dsn); if (db.open()){ qDebug() << "Opened"; return 1; db.close(); } else { qDebug() << "Error = " << db.lastError().text(); return -1; } } This firs