分享

Qt高版本不兼容低版本

 quasiceo 2013-01-13
我安装了Qt by Nokia v4.6.2 (VS2008 OpenSource),但编译一个Qt 3.2的项目时出现如下错误,网上搜了,没有相应的解决方案,除了重新安装3.2的版本外。。。。。

------ 已启动生成: 项目: BMPExporter, 配置: Debug Win32 ------
Uic'ing bmpexptdlg.ui...
uic: File generated with too old version of Qt Designer (3.2)
File 'bmpexptdlg.ui' is not valid

Qt User Interface Compiler version 4.6.2
Usage: D:\Qt-4.6.2\bin\uic [options] <uifile>
  -h, -help                 display this help and exit
  -v, -version              display version
  -d, -dependencies         display the dependencies
  -o <file>                 place the output into <file>
  -tr <func>                use func() for i18n
  -p, -no-protection        disable header protection
  -n, -no-implicit-includes disable generation of #include-directives
                            for forms generated by uic3
  -g <name>                 change generator
moc: bmpexptdlg.h: No such file
Project : error PRJ0019: 某个工具从以下位置返回了错误代码: "Uic'ing bmpexptdlg.ui..."生成日志保存在“file://d:\mitk\3DMed_OpenSource\Code\PluginsDev\VolumeExporter\BMPExporter\Debug\BuildLog.htm”
BMPExporter - 1 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========


请问诸位高手,除了更换低版本的Qt外就没有其它办法?Qt难道就没有向上兼容性?谢谢啦~~


试了一下qt3to4的工具。按照网上的方法。
方法一:
在工程文件*.pro开始处中添加:
QT += qt3support
DEFINES += QT3_SUPPORT
保存,然后运行Qt命令行,切换到所在目录,输入:
qt3to4 *.pro
按照提示,输入a,接着,就开始转换相应的文件。完毕后,再次调试,还是不行,Uic'ing bmpexptdlg.ui 的问题依然存在。。。。。
方法二:
恢复方法一对工程文件的修改。
将qt3to4复制到工程文件medProject.pro所在文件夹,打开命令行,切换到所在目录,输入:
qt3to4 medProject.pro
结果如下:同样输入a
Using rules file: D:\Qt-4.6.2\tools\porting\src\q3porting.xml
Parsing..................................................
Convert file D:\mitk\3DMed_OpenSource\Code\medDocumentUI.ui.h? (Y)es, (N)o, (A)ll         a
Wrote to file: D:\mitk\3DMed_OpenSource\Code\medDocumentUI.ui.h
Wrote to file: D:\mitk\3DMed_OpenSource\Code\medProject.pro
Writing log to portinglog.txt

再次打开vs2008,编译此工程。问题还是没有解决。。。。。。。。。。。。

怪。。。。。。。。。

xtfllbl2010-06-13 10:15
qt在同一大系列里是基本兼容的,比如4.4~4.6.3
但是,在发布一些划时代的版本的时候,比如qt3-qt4的时候,API被进行了大量的重新改写,所以会导致不兼容。
即便如此,qt4还是提供了兼容qt3的一些代码类来弥补。您可以尝试使用 qt3to4 这个小工具来实现

引用
qt3to4 - The Qt 3 to 4 Porting Tool


The qt3to4 tool provides help when moving a project from Qt 3 to Qt 4. It is designed to automate the most tedious part of the porting effort.
See Porting to Qt 4 and Porting UI Files to Qt 4 for more information about porting Qt 3 applications to Qt 4.
Usage
qt3to4 can be run either on individual C++ source or header files, or on an entire project specified by a qmake .pro file:
[pre] qt3to4 myfile.cpp
qt3to4 myapp.pro[/pre]In project mode, qt3to4 reads the .pro file and converts all files specified in it. The tool modifies the files in place. You might want to make a copy of your project before you run the tool.
Porting Rules
The Qt porting tool loads its porting rules from an XML file called q3porting.xml located in Qt's tools/porting/src directory. By editing this file, you can add your own rules or remove some rules.
The standard q3porting.xml file specifies the following conversions:
  • Rename classes that are now part of the Qt 3 support library (e.g., replace QFileDialog with Q3FileDialog).

  • Prefix or rename enum values that have been moved or renamed (e.g., replace QButton::On with QCheckBox::On) or members of the Qt namespace (e.g., replace QWidget::red with Qt::red).

  • Add #include directives that might be needed in Qt 4.

Location of the qt3porting.xml File
You can now specify the location of the qt3porting.xml file with the -f command line option. This is useful if you want to use a modified file with your own rules.
If you you don't want to maintain a modified qt3porting.xml it is possible to create a "patch" file that includes the original file and adds or disables rules. The syntax for this file looks like this:
[pre] <Rules>
   <Include>/path/to/q3porting.xml</Include>

   <item Type="RenamedHeader" Disable="True" >
     <Qt4>q3sqlselectcursor.h</Qt4>
     <Qt3>qsqlselectcursor.h</Qt3>
   </item>

   <item Type="RenamedHeader" >
     <Qt4>newclass.h</Qt4>
     <Qt3>oldclass.h</Qt3>
   </item>
</Rules>[/pre]Logging
The porting tool logs all changes to a file called portinglog.txt in the current directory. This file lists all changes made to the source files.
Advanced Usage
When porting, qt3to4 parses the source files and ports the contents according to the C++ language rules. This C++ parsing step can be disabled with the -disableCppParsing option.
If C++ parsing is enabled, qt3to4 must be able to locate the headers included from the source files. Necessary headers include the public Qt headers and any headers that declares names that may conflict with names in the public Qt headers. The standard C++ headers and system headers are usually not needed.
You can tell qt3to4 where to look for headers by using the -I command-line option. Qt 3.3 header information is built in, so it is normaly not necessary to specify the location of the Qt headers. If you are porting from a different version of Qt 3, you may want to disable the built-in headers with -disableBuiltInQt3Headers, and then add the path to the actual headers with the -I option.
When porting a project, qt3to4 will read the INCLUDEPATH and DEPENDPATH variables from the .pro file and add the paths specified here to the list of include search directories.
To see which headers that are not found, use the -missingFileWarnings option.
Limitations
In some cases, you might get compiler errors because of identifiers in the global namespace (e.g., CTRL). Adding
[pre] using namespace Qt;
[/pre]at the beginning of the source file that contains the indentifier solves the problem.
Legal Notices
Some source code in qt3to4 is licensed under specific highly permissive licenses from the original authors. Nokia gratefully acknowledges these contributions to qt3to4 and all uses of qt3to4 should also acknowledge these contributions and quote the following license statements in an appendix to the documentation.


xtfllbl2010-06-13 11:01
引用

Qt4与Qt3的主要不同
                1)QT4 中提供了大量新控件,虽然它也保持了旧的控件,并命名为Qt3XXX,但是这样的控件没准在今后的哪个QT版本中就不被支持了,所以还是换吧,控件替换的 工作是巨大的,这些新的控件使用了新的方法、属性、和事件名称,虽然是比以前更规范了,但是对于升级旧代码来说,则增加了大量工作。

2)既然要更新控件,那么你就需要使用QDesigner工具来重新画界面了,OK,重画只是纯体力劳动,好说。
界 面画好后,使用uic来根据界面生成代码文件,QT3的uic可以自动生成.h和.cpp文件,假设你在制作一个名叫TestDialog的对话框,那么 QT3的uic生成的文件则是TestDialog.h和TestDialog.cpp,所有的界面初始化工作都在cpp文件中执行,之后程序的逻辑代码 也将加入这个文件,那么对于一个已经完成逻辑功能的对话框来说,如果要修改界面布局,你就不得不重新用uic生成.h和.cpp文件,然后将其中界面相关 的代码复制到你已经修改的文件中,此时决不能直接用uic直接生成到修改过的文件上,因为那样你的代码将全部被冲掉。
这一点上,QT4进步了,因 为QT4中推荐的方法是,使用uic根据界面文件生成一个h文件,以前面的TestDialog为例,生成的文件叫做ui_TestDialog.h,其 中会实现一个名为Ui_TestDialog的类,包含了界面所有控件的加载功能,而程序的逻辑功能依然使用TestDialog.h,和 TestDialog.cpp这两个功能,并在TestDialog.h中用多重继承的方法,从刚才的Ui_TestDialog类来继承出实际的 TestDialog类,在TestDialog的构造函数中,只需要使用Ui_TestDialog::setupUi()方法,就可以构建出整个界 面,并且由于是从Ui_TestDialog继承来的,在逻辑代码中也可以方便的访问所有控件。
从这一点来说,QT4的方法是个巨大的进步,因为ui_xxx.h中不再包含任何用户自己写的代码了,此时你想更改界面布局的话,只需要用QDesigner修改界面,再用uic生成ui_xxx.h文件,直接替换原文件就可以了。
当然,QT的ui_xxx.h文件还有其它的使用方法,不一定要使用多重继承的方法,在这里我只是介绍了我认为最方便的方法。
另外,如果你所设计的界面比较复杂,需要将某部分界面独立在其它Widget中设计和写逻辑代码,那么最上层的Dialog的ui_xxx.h文件还是需要手动修改的,不过相对于QT3,这样的修改还是非常简单的。
最后要指出的是,虽然是个好设计,但是由于和QT3的巨大区别,这导致了我重写所有界面相关的代码。。。。痛苦哦。

3)QThread 发生了巨大的改变,新的QThread是从QObject继承而来的,因此可以在QThread中直接使用signal/slot了,它们是线程安全的。 以前的QApplication::postEvent()方法没有了,我以前实现的一整套防止线程阻塞的机制也不再需要了。不过确实是很不错进步。

4)QSocketDevice这样的底层socket连接控件没有了,QSocket也没有了,换而之的是QTcpSocket和QTcpServer,QTcpSocket即可以用异步方式调用,又可以在线程中,用同步方式等待数据到达。

5)QT 的h文件不再混在一起了,而是分成Core,Gui,Network,Xml,OpenGL等等子文件夹,所有include都需要重写了,写成 “#include <QtCore/QObject>”的样子。不过相对于前面的修改来说,这些实在不足挂齿了。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多