Learn Qt 5
eBook - ePub

Learn Qt 5

Nicholas Sherriff (Nick)

Buch teilen
  1. 346 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Learn Qt 5

Nicholas Sherriff (Nick)

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Learn the fundamentals of QT 5 framework to develop interactive cross-platform applicationsAbout This Book• A practical guide on the fundamentals of application development with QT 5• Learn to write scalable, robust and adaptable C++ code with QT• Deploy your application on different platforms such as Windows, Mac OS, and LinuxWho This Book Is ForThis book is for application developers who want a powerful and flexible framework to create modern, responsive applications on Microsoft Windows, Apple Mac OS X, and Linux desktop platforms. You should be comfortable with C++ but no prior knowledge of Qt or QML is required.What You Will Learn• Install and configure the Qt Framework and Qt Creator IDE• Create a new multi-project solution from scratch and control every aspect of it with QMake• Implement a rich user interface with QML• Learn the fundamentals of QtTest and how to integrate unit testing• Build self-aware data entities that can serialize themselves to and from JSON• Manage data persistence with SQLite and CRUD operations• Reach out to the internet and consume an RSS feed• Produce application packages for distribution to other usersIn DetailQt is a mature and powerful framework for delivering sophisticated applications across a multitude of platforms. It has a rich history in the Linux world, is widely used in embedded devices, and has made great strides in the Mobile arena over the past few years. However, in the Microsoft Windows and Apple Mac OS X worlds, the dominance of C#/.NET and Objective-C/Cocoa means that Qt is often overlooked.This book demonstrates the power and flexibility of the Qt framework for desktop application development and shows how you can write your application once and deploy it to multiple operating systems. Build a complete real-world line of business (LOB) solution from scratch, with distinct C++ library, QML user interface, and QtTest-driven unit-test projects.This is a suite of essential techniques that cover the core requirements for most LOB applications and will empower you to progress from a blank page to shipped application.Style and approachThis book takes a hands-on approach to app development that emphasizes the key concepts while you're doing the project work.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Learn Qt 5 als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Learn Qt 5 von Nicholas Sherriff (Nick) im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Programming in C++. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2018
ISBN
9781788473682

Persistence

In Chapter 5, Data, we created a framework for capturing and holding data in memory. However, this is only half of the story, as without persisting the data to some external destination, it will be lost as soon as we close the application. In this chapter, we will build on our earlier work and save our data to disk in a SQLite database so that it can live on beyond the lifetime of the application. Once saved, we will also build methods for finding, editing, and deleting our data. To get all these operations for free in our various data models, we will extend our data entities so that they can load and save to our database automatically, without us having to write boilerplate code in each class. We will cover the following topics:
  • SQLite
  • Primary keys
  • Creating clients
  • Finding clients
  • Editing clients
  • Deleting clients

SQLite

General purpose database technology has fragmented in the recent years with the explosion of NoSQL and Graph databases. However, SQL databases are still fighting fit and absolutely an appropriate choice in a lot of applications. Qt comes with built-in support for several SQL database driver types, and can be extended with custom drivers. MySQL and PostgreSQL are very popular open source SQL database engines and are both supported by default, but are intended for use on servers and require administration, which makes them a bit unnecessarily complicated for our purposes. Instead, we will use the much more lightweight SQLite, which is commonly used as a client-side database and is very popular in mobile applications due to its small footprint.
According to the official website at https://www.sqlite.org, "SQLite is a self-contained, high-reliability, embedded, full-featured, public-domain, SQL database engine. SQLite is the most used database engine in the world". Paired with Qt's SQL related classes, it's a snap to create a database and store your data.
The first thing we need to do is add the SQL module to our library project to get access to all of Qt’s SQL goodness. In cm-lib.pro, add the following:
QT += sql
Next, we’ll take onboard what we discussed in the previous chapter and implement our database-related functionality behind an interface. Create a new i-database-controller.h header file in cm-lib/source/controllers:
#ifndef IDATABASECONTROLLER_H #define IDATABASECONTROLLER_H #include <QJsonArray> #include <QJsonObject> #include <QList> #include <QObject> #include <QString> #include <cm-lib_global.h> namespace cm { namespace controllers { class CMLIBSHARED_EXPORT IDatabaseController : public QObject { Q_OBJECT public: IDatabaseController(QObject* parent) : QObject(parent){} virtual ~IDatabaseController(){} virtual bool createRow(const QString& tableName, const QString& id, 
const QJsonObject& jsonObject) const = 0;
virtual bool deleteRow(const QString& tableName, const QString& id)
const = 0;
virtual QJsonArray find(const QString& tableName, const QString&
searchText) const = 0;
virtual QJsonObject readRow(const QString& tableName, const
QString& id) const = 0;
virtual bool updateRow(const QString& tableName, const QString& id,
const QJsonObject& jsonObject) const = 0;
}; }} #endif
Here, we are implementing the four basic functions of (Create, Read, Update, and Delete) CRUD, which are relevant to persistent storage in general, not just SQL databases. We supplement these functions with an additional find() method that we will use to find an array of matching clients based on supplied search text.
Now, let’s create a concrete implementation of the interface. Create a new DatabaseController class in cm-lib/source/controllers.
database-controller.h:
#ifndef DATABASECONTROLLER_H #define DATABASECONTROLLER_H #include <QObject> #include <QScopedPointer> #include <controllers/i-database-controller.h> #include <cm-lib_global.h> namespace cm { namespace controllers { class CMLIBSHARED_EXPORT DatabaseController : public IDatabaseController { Q_OBJECT public: explicit DatabaseController(QObject* parent = nullptr); ~DatabaseController(); bool createRow(const QString& tableName, const QString& id, const 
QJsonObject& jsonObject) const override;
bool deleteRow(const QString& tableName, const QString& id) const
override;
QJsonArray find(const QString& tableName, const QString&
searchText) const override;
QJsonObject readRow(const QString& tableName, const QStrin...

Inhaltsverzeichnis