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

相关文章

Java 线程安全与 volatile与单例模式问题及解决方案

《Java线程安全与volatile与单例模式问题及解决方案》文章主要讲解线程安全问题的五个成因(调度随机、变量修改、非原子操作、内存可见性、指令重排序)及解决方案,强调使用volatile关键字... 目录什么是线程安全线程安全问题的产生与解决方案线程的调度是随机的多个线程对同一个变量进行修改线程的修改操

Redis出现中文乱码的问题及解决

《Redis出现中文乱码的问题及解决》:本文主要介绍Redis出现中文乱码的问题及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1. 问题的产生2China编程. 问题的解决redihttp://www.chinasem.cns数据进制问题的解决中文乱码问题解决总结

SQLite3 在嵌入式C环境中存储音频/视频文件的最优方案

《SQLite3在嵌入式C环境中存储音频/视频文件的最优方案》本文探讨了SQLite3在嵌入式C环境中存储音视频文件的优化方案,推荐采用文件路径存储结合元数据管理,兼顾效率与资源限制,小文件可使用B... 目录SQLite3 在嵌入式C环境中存储音频/视频文件的专业方案一、存储策略选择1. 直接存储 vs

全面解析MySQL索引长度限制问题与解决方案

《全面解析MySQL索引长度限制问题与解决方案》MySQL对索引长度设限是为了保持高效的数据检索性能,这个限制不是MySQL的缺陷,而是数据库设计中的权衡结果,下面我们就来看看如何解决这一问题吧... 目录引言:为什么会有索引键长度问题?一、问题根源深度解析mysql索引长度限制原理实际场景示例二、五大解决

Springboot如何正确使用AOP问题

《Springboot如何正确使用AOP问题》:本文主要介绍Springboot如何正确使用AOP问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录​一、AOP概念二、切点表达式​execution表达式案例三、AOP通知四、springboot中使用AOP导出

Python中Tensorflow无法调用GPU问题的解决方法

《Python中Tensorflow无法调用GPU问题的解决方法》文章详解如何解决TensorFlow在Windows无法识别GPU的问题,需降级至2.10版本,安装匹配CUDA11.2和cuDNN... 当用以下代码查看GPU数量时,gpuspython返回的是一个空列表,说明tensorflow没有找到

解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题

《解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题》:本文主要介绍解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4... 目录未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘打开pom.XM

IDEA Maven提示:未解析的依赖项的问题及解决

《IDEAMaven提示:未解析的依赖项的问题及解决》:本文主要介绍IDEAMaven提示:未解析的依赖项的问题及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝... 目录IDEA Maven提示:未解析的依编程赖项例如总结IDEA Maven提示:未解析的依赖项例如

Redis分片集群、数据读写规则问题小结

《Redis分片集群、数据读写规则问题小结》本文介绍了Redis分片集群的原理,通过数据分片和哈希槽机制解决单机内存限制与写瓶颈问题,实现分布式存储和高并发处理,但存在通信开销大、维护复杂及对事务支持... 目录一、分片集群解android决的问题二、分片集群图解 分片集群特征如何解决的上述问题?(与哨兵模

SpringBoot+Redis防止接口重复提交问题

《SpringBoot+Redis防止接口重复提交问题》:本文主要介绍SpringBoot+Redis防止接口重复提交问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不... 目录前言实现思路代码示例测试总结前言在项目的使用使用过程中,经常会出现某些操作在短时间内频繁提交。例