📜 ⬆️ ⬇️

QtContribs = Harbor + QT

Good day.

In the post “Harbor - the new face of xBase family”, Alexander Kresin told about Harbor.
The QtContribs project is a Harbor extension for using Qt.

Those. everyone who is familiar with dbase programming languages ​​(foxpro, clipper, etc.) will be able, using QtContribs, to write cross-platform applications with a good graphical interface (of course, having studied the "philosophy" of Qt), and generally use the full power of Qt.
')
Considering the above in the post “Developing a Qt application with access to MySQL for Android” , the possibilities for developing for Android + mySQL also exist.

But the main developer of the QtContribs library (Pritpal Bedi) is conservative and does not develop the part related to QtSql.
I considered this wrong and took a little part in the development of this direction.

(Corrected) Today (07/25/2014), the main developer of QtContribs Pritpal Bedi, after looking at my work, laid out new binding for QtSql and said that he would develop this area. The QtContribs forum is great.

Next, I will show an example of using QSqlTableModel and QTableView.

So, in the Qt delivery there are many examples, and among them is the sqlbrowser application. I took a browserwidget.ui file from it - this is an application window made in qt-designer, and fixed it a bit.

Prepared a project.

For the connection of Harbor and Qt objects, files with the qth extension are made - cpp-files are generated from them (bindigs or simpler bundles).
I put two qth files in the project archive.

The whole project for Linux is here: the QtContribs forum .

Made the main program at Harbor:

#include "hbqtgui.ch" #include "hbqtsql.ch" STATIC s_db, s_oBrowser PROC main() LOCAL oMainWindow, oELoop, lExit := .F.//, oApp LOCAL oStrModel, oStrList//, db CLS hb_cdpSelect( "UTF8EX" )//    oMainWindow := QMainWindow() oMainWindow:setAttribute( Qt_WA_DeleteOnClose, .F. ) oMainWindow:setWindowTitle("Qt SQL Browser") s_oBrowser = hbqtui_browserwidget(oMainWindow) oMainWindow:setCentralWidget(s_oBrowser:oWidget) oMainWindow:connect( QEvent_Close , {|| lExit := .T. } ) s_db = QSqlDatabase():addDatabase("QMYSQL") s_db:setHostName("localhost") s_db:setDatabaseName("test") IF .NOT. s_db:open() ?"Not Connected!" RETURN ENDIF oStrList :=s_db:tables() oStrModel := QStringListModel( oStrList, s_oBrowser:listView ) s_oBrowser:listView:setModel( oStrModel ) s_oBrowser:listView:connect( "clicked(QModelIndex)", { |d| showTable(d) } ) oMainWindow:show() oELoop := QEventLoop( oMainWindow ) DO WHILE .t. oELoop:processEvents() IF lExit EXIT ENDIF ENDDO oELoop:exit( 0 ) RETURN PROCEDURE showTable(d) LOCAL cTName LOCAL model cTName := s_oBrowser:listView:model():data(d, 0):ToString() cTName := s_db:driver:escapeIdentifier(cTName, 1/*QSqlDriver():IdentifierType:TableName*/) model := QSqlTableModel(s_oBrowser:table, s_db) model:setTable(cTName) if (model:lastError():type() != 0) ?model:lastError():text() endif model:select() if (model:lastError():type() != 0) ??model:lastError():text() endif s_oBrowser:table:setModel(model) // s_oBrowser:table:setEditTriggers(QAbstractItemView_DoubleClicked+QAbstractItemView_EditKeyPressed) RETURN 


It turned out this:

image

That's all seemingly.

But for this to work, the qtmysql driver is needed - its compilation is a system issue, and I briefly described how to do this on the forum.

For those who are interested, I suggest watching the tutorial of developing simple QtContribs-applications: HBQT-Tutorial .

I invite everyone with free time and willing to understand C, C ++ and other languages ​​to develop the project. In the near future, the community plans to integrate the debugger into the Harbor IDE (abbreviated HbIDE).

If you have questions (need information in Russian) how to collect and use Harbor and QtContribs, what HbIDE is and how to use it, and others, then I am ready to continue ...

Download source codes and executables in this repository sourceforge.net

Source: https://habr.com/ru/post/230801/


All Articles