Qt: Qt classes vs. standard C++

柔情痞子 提交于 2019-12-30 08:30:08

问题


A large amount of functionality is duplicated between standard c++ and Qt. At some point it seems logical but many times it looks foolish. Like I feel like doing a new programming language, learning things which I already know. e.g. using QFile.

Also if I do it all Qt way and suppose now I want to move out of Qt framework it will be too much tedious to rewrite that code. OTOH I like Qt because it provides me with libraries which otherwise I would have to fish myself like webkit, database connectivity, dbus etc.

What do you suggest mix standard C++ or do it pure Qt way?


回答1:


As there is no GUI in C++ you should abstract the GUI code from the rest of the real code.

Then within your QT implementation of your GUI abstraction feel free to use QT code.
You will also then be able to write Wx/Quartz GUI abstraction without affecting the real code.

In the real code (were the work is done) stick to standard stuff (or cross platform libs that are nearly standard (boost)). One could argue that QT is cross platform. Just remember that that using a lib here will be tightly coupling your code the lib, thus extracting it latter date will be non trivial. (see the previous question about removing Rouge Wave from a legacy application)




回答2:


I do all the collection classes in std:: it's clearer for non Qt developers and more portable.

Strings and stringlists I use the Qt ones inside a purely Qt function that is doing something GUI-ish but otherwise use std::String. Although the Qt .arg() formatting is a lot nicer than stringstream



来源:https://stackoverflow.com/questions/3523622/qt-qt-classes-vs-standard-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!