Beginner needs help
-
I am new to qt and c++ and I don't know where to start. I am a part-time programmer for 20 years now, starting with basic and moving to object oriented languages, at last this was xojo. I became disappointed with their linux support and the lack of modern technics - they don't even have a 64bit version. So I decided it was time for a move.
I mostly do database apps accessing a SQL server. So the basic function of my programs is: get data from the server, display it in a UI and let the user change and store it again. Or do some processing and display/print the gathered informations. Nothing unusual, I guess.
I am quite bewildered with the many possible options of Qt. I have seen videos on the new Qt Quick and QML features and decided to go this way. But is there a chance to hook a QML UI to a SQL server? I understood that I needed a model. But my databases are relational and use many joins, so the provided models don't seem to fit my needs.
I have seen a lot of information on this topic, some of it fairly outdated. So to bring a long story to an end: I need some advice where to look, what examples to rework, what documentation to read. Anything that will help me in understanding and getting back to developing would be helpful.
-
Hi, and welcome to the Qt Dev Net!
I've only ever used Qt's SQLite driver in C++, so I don't know what integration with QML is like. However, these pages should provide a good general starting point (they contain many links to other pages too):
- "SQL Programming":http://qt-project.org/doc/qt-5/sql-programming.html
- "SQL Examples":http://qt-project.org/doc/qt-5/examples-sql.html
Also, have you seen the "QSqlRelationalTableModel":http://qt-project.org/doc/qt-5/QSqlRelationalTableModel.html ?
-
Gene,
first of all: thank you for your interest and help. I have already read many of the links you provided, although some is new.
I was wondering if there is a way to do all this in QML. I have already designed a basic UI in QML and I can't figure out how to link this UI to my SQL database. I tried to avoid c++ as far as possible and I also have read that the new Qt Quick Components supersede the older widgets. I don't want to learn stuff that becomes obsolete in some time ;)
Harvey
-
I don't know how to talk to SQL databases in QML. You can wait for someone else to come along to answer your question here, or you can subscribe to the "Interest mailing list":http://lists.qt-project.org/mailman/listinfo/interest and ask there -- there are more experts there. You can also try to use widgets.
Please don't worry about Qt Widgets becoming obsolete. It may be old, but it is a very mature and reliable technology. New features and bug fixes are still being produced for Qt Widgets today -- it will be around for a long time still!
QML/Qt Quick is good for making fluid (animated, sliding) user interfaces that you see on smartphones/tablets. However, if you want a traditional desktop office GUI, Qt Widgets is currently more powerful.
It is also possible to create a hybrid QML + Widgets GUI. You could create a widget-based table view in C++ (to interact with a QSelRelationalTableModel), and create the rest in QML.
If you are looking for a new OO language to replace Xojo, I'd highly recommend C++ with Qt :) Note that QML is designed mostly for GUIs only. Business logic should still be implemented in C++.
Good luck!
-
You can also just expose the data model to QML. Managing the data from C++ (I really, really doubt that's about to get "obsolete" any time soon!) and building your GUI in QML (I'd bet on QML becoming obsolete way before C++ does, but hopefully neither will in the next few years).
Having said that, I think dat especially SQL models would lend themselves very well to the QML world. The SQL (select) language really is a declarative language too, after all. So I guess bindings would be quite natural.
-
I thank both of you for your opinions. I guess I do it the 'hard' way with C++ and the widgets. Not because I am convinced but because this is much better documented than the QML / SQL relation is. I get the feeling that QML is more for the mobile world than for my office applications.
-
Good luck with your project! Please feel free to ask if you have any more questions.
Yes, QML was invented by Nokia for creating mobile apps.