qt4环境下跑qt3程序的遇到的小问题

2024-01-14 11:08
文章标签 问题 程序 环境 遇到 qt4 qt3

本文主要是介绍qt4环境下跑qt3程序的遇到的小问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

qt4环境下跑qt3程序的遇到的小问题

 

参考资料:<<C++ GUI Programming with Qt 3 >>英文版

 

 1 今天跑了书上一个例子,是QT3写的,但我只有QT4的环境,所以出现了一点问题~~一开始没有看QT4的文档

看如何运行QT3的程序,所以直接看API修改源代码,代码如下(QT4环境下运行QT3程序的方法见下面2

#include <iostream>

//这是<<C++ GUI Programming with Qt 3 >>书上一个例子,因为我机器上的QT版本是4.2.2,结果
//
编译起来接口不一致,弄的好烦~~好不容易看了API改的程序能跑起来了~~还是有点小问题,没时间,现不改了

#include <QChar>
#include <QDir>
#include <QString>
#include <QStringList>

using namespace std;

int imageSpace(const QString &path) {
    QDir dir(path);
    QStringList::Iterator it;
    int size = 0;

    const QString qs("*.jpg");
    const QStringList st(qs);
    //const QString qs1(" *.png");
    //const QString qs2(" *.jpeg");
    //st.join(qs1);
    //st.join(qs2);

   
    QStringList files = dir.entryList(st,
                                      QDir::Files);


    it = files.begin();

    while (it != files.end()) {
        size += QFileInfo(path, *it).size();
        ++it;
    }

    cout << "size-->" << size << endl;

    QStringList dirs = dir.entryList(QDir::Dirs);
    it = dirs.begin();
    while (it != dirs.end()) {
        if (*it != "." && *it != "..")
            size += imageSpace(path + "/" + *it);
        ++it;
    }
    return size;
}

void printQString(QString s) {
    const QChar* c = s.unicode();
    int i=0;
    while (true) {
        if (c[i].toLatin1()!='/0') {
            cout << c[i].toLatin1();
        } else {
            cout << "/n";
            break;
        }
        i++;
    }
}

 

int main(int argc, char *argv[]) {


  //QT3
中的currentDirPath()--->QT4currentPath()
  QString path = QDir::currentPath();


    if (argc > 1)
        path = argv[1];

    cout << "Space used by images in " ;

 //QT4找不到QStringpath.ascii()方法,只能自己写了个printQString函数打印QString调试,烦死了!(可能我没找到)
 printQString(path);

    cout << " and its subdirectories is "
    << (imageSpace(path) / 1024) << " KB" << endl;

    return 0;
}

 

 

2 看了QT4.2.2的文档,发现可以用QT4来编译QT3的程序的

Add the line QT += qt3support to your .pro file if you use qmake; otherwise, edit your makefile or project file to link against the Qt3Support library and add -DQT3_SUPPORT to your compiler flags. (You might also need to specify other libraries. See What's New in Qt 4 for details.)

就是在qmake -project 生成的XX.pro文件只能够加上一行QT += qt3support


 

######################################################################
# Automatically generated by qmake (2.01a) ??? ?? 5 20:03:41 2007
######################################################################

TEMPLATE = app
TARGET =
DEPENDPATH += . release
INCLUDEPATH += .

QT += qt3support       //就是这行

# Input
SOURCES += ImageSpace.cpp release/HelloQT.cpp

 

然后qmake ,最后make 就行了(QT3的程序代码如下)

#include <iostream>
#include <QDir>

using namespace std;

int imageSpace(const QString &path)
{
    QDir dir(path);
    QStringList::Iterator it;
    int size = 0;

    QStringList files = dir.entryList("*.png *.jpg *.jpeg",
                                      QDir::Files);
    it = files.begin();
    while (it != files.end()) {
        size += QFileInfo(path, *it).size();
        ++it;
    }

    QStringList dirs = dir.entryList(QDir::Dirs);
    it = dirs.begin();
    while (it != dirs.end()) {
        if (*it != "." && *it != "..")
            size += imageSpace(path + "/" + *it);
        ++it;
    }
    return size;
}


int main(int argc, char *argv[]) {
    QString path = QDir::currentDirPath();
    if (argc > 1)
        path = argv[1];

    cerr << "Space used by images in " << endl
    << path.ascii() << endl
    << "and its subdirectories is"
    << (imageSpace(path) / 1024) << " KB" << endl;

    return 0;
}


 

但是程序运行后,没有任何显示?(解决方法看3

3 因为程序编译没有问题,链接也没有问题~~那问题出在哪里呢?

我猜想可能出现链接的参数上面

g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runt
ime-pseudo-reloc -Wl,-subsystem,windows -o "debug/__GUI_Programming_with_Qt3.exe
" debug/ImageSpace.o debug/HelloQT.o  -L"d:/Qt/4.2.2/lib" -lmingw32 -lqtmaind -l
Qt3Supportd4 -lQtGuid4 -lQtCored4

就是这个参数作怪,这个是qmake自动生成~~只要把这行去掉,程序运行就没有问题了!

-Wl表示这个参数是是gcc编译器传给连接器的参数。(这个参数在网上没有查找到意思,希望知道的兄弟回个帖)

其他几个传给连接器的参数,我在网上找了下资料(只找到下面几个)

--disable-stdcall-fixup

If the link finds a symbol that it cannot resolve, it will attempt to do "fuzzy linking" by looking for another defined symbol that differs only in the format of the symbol name (cdecl vs stdcall) and will resolve that symbol by linking to the match. For example, the undefined symbol _foo might be linked to the function _foo@12, or the undefined symbol _bar@16 might be linked to the function _bar. When the linker does this, it prints a warning, since it normally should have failed to link, but sometimes import libraries generated from third-party dlls may need this feature to be usable. If you specify `--enable-stdcall-fixup', this feature is fully enabled and warnings are not printed. If you specify `--disable-stdcall-fixup', this feature is disabled and such mismatches are considered to be errors.

4 最后程序运行正常!

Space used by images in
D:/Qt/__GUI_Programming_with_Qt3/debug
and its subdirectories is109 KB

 

 

这篇关于qt4环境下跑qt3程序的遇到的小问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/604934

相关文章

使用雪花算法产生id导致前端精度缺失问题解决方案

《使用雪花算法产生id导致前端精度缺失问题解决方案》雪花算法由Twitter提出,设计目的是生成唯一的、递增的ID,下面:本文主要介绍使用雪花算法产生id导致前端精度缺失问题的解决方案,文中通过代... 目录一、问题根源二、解决方案1. 全局配置Jackson序列化规则2. 实体类必须使用Long封装类3.

Idea插件MybatisX失效的问题解决

《Idea插件MybatisX失效的问题解决》:本文主要介绍Idea插件MybatisX失效的问题解决,详细的介绍了4种问题的解决方法,具有一定的参考价值,感兴趣的可以了解一下... 目录一、重启idea或者卸载重装MyBATis插件(无需多言)二、检查.XML文件与.Java(该文件后缀Idea可能会隐藏

Nginx 访问 /root/下 403 Forbidden问题解决

《Nginx访问/root/下403Forbidden问题解决》在使用Nginx作为Web服务器时,可能会遇到403Forbidden错误,文中通过示例代码介绍的非常详细,对大家的学习或者工作... 目录解决 Nginx 访问 /root/test/1.html 403 Forbidden 问题问题复现Ng

Python的pip在命令行无法使用问题的解决方法

《Python的pip在命令行无法使用问题的解决方法》PIP是通用的Python包管理工具,提供了对Python包的查找、下载、安装、卸载、更新等功能,安装诸如Pygame、Pymysql等Pyt... 目录前言一. pip是什么?二. 为什么无法使用?1. 当我们在命令行输入指令并回车时,一般主要是出现以

Nginx部署React项目时重定向循环问题的解决方案

《Nginx部署React项目时重定向循环问题的解决方案》Nginx在处理React项目请求时出现重定向循环,通常是由于`try_files`配置错误或`root`路径配置不当导致的,本文给大家详细介... 目录问题原因1. try_files 配置错误2. root 路径错误解决方法1. 检查 try_f

Java使用WebView实现桌面程序的技术指南

《Java使用WebView实现桌面程序的技术指南》在现代软件开发中,许多应用需要在桌面程序中嵌入Web页面,例如,你可能需要在Java桌面应用中嵌入一部分Web前端,或者加载一个HTML5界面以增强... 目录1、简述2、WebView 特点3、搭建 WebView 示例3.1 添加 JavaFX 依赖3

防止SpringBoot程序崩溃的几种方式汇总

《防止SpringBoot程序崩溃的几种方式汇总》本文总结了8种防止SpringBoot程序崩溃的方法,包括全局异常处理、try-catch、断路器、资源限制、监控、优雅停机、健康检查和数据库连接池配... 目录1. 全局异常处理2. 使用 try-catch 捕获异常3. 使用断路器4. 设置最大内存和线

Python解决雅努斯问题实例方案详解

《Python解决雅努斯问题实例方案详解》:本文主要介绍Python解决雅努斯问题实例方案,雅努斯问题是指AI生成的3D对象在不同视角下出现不一致性的问题,即从不同角度看物体时,物体的形状会出现不... 目录一、雅努斯简介二、雅努斯问题三、示例代码四、解决方案五、完整解决方案一、雅努斯简介雅努斯(Janu

MySQL索引失效问题及解决方案

《MySQL索引失效问题及解决方案》:本文主要介绍MySQL索引失效问题及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mysql索引失效一、概要二、常见的导致MpythonySQL索引失效的原因三、如何诊断MySQL索引失效四、如何解决MySQL索引失

一文教你如何解决Python开发总是import出错的问题

《一文教你如何解决Python开发总是import出错的问题》经常朋友碰到Python开发的过程中import包报错的问题,所以本文将和大家介绍一下可编辑安装(EditableInstall)模式,可... 目录摘要1. 可编辑安装(Editable Install)模式到底在解决什么问题?2. 原理3.