简体   繁体   English

现有C ++项目的Qt UI

[英]Qt UI for existing C++ project

I have already written a C++ program and I would like to write a GUI for it. 我已经编写了一个C ++程序,我想为它编写一个GUI。 I realize Qt is a wonderful tool, however, Qt has it's own classes, which make me quite confused. 我意识到Qt是一个很棒的工具,但是,Qt有它自己的类,这让我很困惑。 eg: instead of String, Qt has a class named QString.. 例如:Qt有一个名为QString的类,而不是String。

I am wondering if I can mix C++ code and Qt code in C++? 我想知道我是否可以在C ++中混合使用C ++代码和Qt代码?

Yes you can intermix Qt and STL very easily. 是的,你可以很容易地混合Qt和STL。

The GUI takes QString s but will silently create these form std::string or char* , QStrings returned from Qt can be converted with toStdString() or toAscii() . GUI接受QString但是会静默地创建这些形式的std::stringchar* ,从Qt返回的QStrings可以用toStdString()toAscii()

Qt includes a set of collection classes but you don't have to use them. Qt包含一组集合类,但您不必使用它们。

Qt does a good job of looking like modern C++, there are a few 'extras' to handle the signal and slot event mechanism but these are more a complication to the build environment than to the code. Qt很好地看起来像现代C ++,有一些'额外'来处理信号和插槽事件机制,但这些更多是构建环境的复杂性而不是代码。

edit:thanks bill 编辑:谢谢账单

I wont recommend mixing std c++ code and Qt code together. 我不建议将std c ++代码和Qt代码混合在一起。

Let's say, your c++ code is the logic then the Qt code , should be just for GUI. 比方说,你的c ++代码是Qt代码的逻辑,应该只用于GUI。 Using a MVC/MVP patterns or likewise, separate your logic and UI. 使用MVC / MVP模式或类似方法,分离您的逻辑和UI。

Thus,it would be easier in the future to be able to run your code with/without using a UI. 因此,将来可以更轻松地使用/不使用UI来运行代码。

in short, yes you can! 总之,是的,你可以! for example, a QString is essentially a string and has a toAscii() method, so you can easily use Qt for your projects. 例如,QString本质上是一个字符串,并且具有toAscii()方法,因此您可以轻松地将Qt用于您的项目。 Although you MIGHT run into some problems integrating Qt into visual studio (assuming you are using it), you will be able to mix c++ code and Qt code(which is in c++) 虽然你可能遇到将Qt集成到visual studio中的一些问题(假设你正在使用它),你将能够混合c ++代码和Qt代码(在c ++中)

yeah! 是啊! Qt is something you can use in your C++ code. Qt是你可以在C ++代码中使用的东西。 Qt is mainly for GUI but it is good classes for Socket, Containers, Network, ... You are free to use STL and other normal classes or the ones Qt offers you. Qt主要用于GUI,但它是Socket,Containers,Network等的好类。您可以自由使用STL和其他普通类或Qt为您提供的类。 The biggest point is that if you use Qt in your code before the main Compile you should do a meta compile to make it ready for you compiler. 最重要的一点是,如果你在主编译之前的代码中使用Qt,你应该进行元编译,以便为编译器做好准备。 One thing you should notice is that Qt is not standard it means although it supports Windows, Linux and Mac OS, it won't be usable on other platforms. 你应该注意的一点是,Qt不是标准的,它意味着虽然它支持Windows,Linux和Mac OS,但它不能在其他平台上使用。

They can be used together. 它们可以一起使用。

C++ has a long history and the STL implementation and support have evolved with the language. C ++有着悠久的历史,STL的实现和支持随着语言的发展而发展。 I think that the ex-Trolltech team decided that they didn't have enough control over the quality and availability of STL implementations to make the Qt library depend on it. 我认为前Trolltech团队认为他们对STL实现的质量和可用性没有足够的控制权来使Qt库依赖它。 The result is that Qt has its own QTL, QtAlgorithms header and QString. 结果是Qt有自己的QTL,QtAlgorithms头和QString。

They have taken care to make them compatible with the STL: 他们注意使它们与STL兼容:

  • most containers have a similar interface to the STL ones (eg: iterator access, push_back(), empty(), etc) 大多数容器都有与STL类似的接口(例如:iterator access,push_back(),empty()等)
  • Qt containers can be converted to/from STL containers (eg: QVector::toStdVector, QList::fromStdList) Qt容器可以转换为STL容器(例如:QVector :: toStdVector,QList :: fromStdList)
  • Qt containers can be used with STL algorithms Qt容器可以与STL算法一起使用
  • QString can be converted to/from std::string and std::wstring with toStd(W)String / fromStd(W)String 可以使用toStd(W)String / fromStd(W)String将QString转换为std :: string和std :: wstring

Personally, I like QString more than std::string, it is easier to use and more powerful. 就个人而言,我喜欢QString而不是std :: string,它更容易使用,功能更强大。

Yes you can. 是的你可以。

I actually made a Qt-GUI-wrapper for a set of C based functions. 我实际上为一组基于C的函数制作了一个Qt-GUI包装器。 No problems with the Qt integration, only the low level C (which leaks memory...). Qt集成没有问题,只有低级别C(泄漏内存......)。

See here: http://code.google.com/p/qhocr/ 请参阅此处: http//code.google.com/p/qhocr/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM