QtContribs = Harbor + QT

Good day.

In a post “Harbor - the new face of xBase family” Alexander Kresin told what Harbor is.
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 indeed use the full power of Qt.

Considering the “Development of a Qt-application with access to MySQL for Android” , the development opportunities for Android + mySQL also exist.

But the main developer of the QtContribs library (Pritpal Bedi) is conservative and does not develop the part that is associated with QtSql.
I thought it was wrong and participated a bit in the development of this area.

(Fixed) Today (07/25/2014) the main developer of QtContribs Pritpal Bedi, having looked at my work, posted new bindings for QtSql and said that it would develop this area. QtContribs forum This is great.

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

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

Prepared a project.

To connect Harbor and Qt objects, files with the qth extension were made - cpp-files are generated from them (binders or simpler bundles).
I put two qth files in the project archive.

The entire Linux project is here: the QtContribs forum .

Made the main program on Harbor:

#include "hbqtgui.ch"
#include "hbqtsql.ch"
STATIC s_db, s_oBrowser
PROC main()
   LOCAL oMainWindow, oELoop, lExit := .F.//, oApp
   LOCAL oStrModel, oStrList//, db
   hb_cdpSelect( "UTF8EX" )//Основная кодовая страница приложения
   oMainWindow := QMainWindow()
   oMainWindow:setAttribute( Qt_WA_DeleteOnClose, .F. )
   oMainWindow:setWindowTitle("Qt SQL Browser")
   s_oBrowser = hbqtui_browserwidget(oMainWindow)
   oMainWindow:connect( QEvent_Close   , {|| lExit := .T. } )
   s_db = QSqlDatabase():addDatabase("QMYSQL")
   IF .NOT. s_db:open()
      ?"Not Connected!"
   oStrList :=s_db:tables()
   oStrModel := QStringListModel( oStrList, s_oBrowser:listView )
   s_oBrowser:listView:setModel( oStrModel )
   s_oBrowser:listView:connect( "clicked(QModelIndex)", { |d| showTable(d) } )
   oELoop := QEventLoop( oMainWindow )
   DO WHILE .t.
      IF lExit
   oELoop:exit( 0 )
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)
    if (model:lastError():type() != 0)
    if (model:lastError():type() != 0)
//    s_oBrowser:table:setEditTriggers(QAbstractItemView_DoubleClicked+QAbstractItemView_EditKeyPressed)

It turned out this:


That’s all, it would seem.

But for this to work, you need the qtmysql driver - compiling it is a system issue, I also briefly described how to do this on the forum.

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

I invite everyone who has free time and wants to understand C, C ++ and other languages ​​to the development of the project. In the near future, community debugger integration in the Harbor IDE (abbreviated as HbIDE).

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

You can download the source and executable files in this repositorysourceforge.net

Also popular now: