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

相关文章

Spring的RedisTemplate的json反序列泛型丢失问题解决

《Spring的RedisTemplate的json反序列泛型丢失问题解决》本文主要介绍了SpringRedisTemplate中使用JSON序列化时泛型信息丢失的问题及其提出三种解决方案,可以根据性... 目录背景解决方案方案一方案二方案三总结背景在使用RedisTemplate操作redis时我们针对

Kotlin Map映射转换问题小结

《KotlinMap映射转换问题小结》文章介绍了Kotlin集合转换的多种方法,包括map(一对一转换)、mapIndexed(带索引)、mapNotNull(过滤null)、mapKeys/map... 目录Kotlin 集合转换:map、mapIndexed、mapNotNull、mapKeys、map

nginx中端口无权限的问题解决

《nginx中端口无权限的问题解决》当Nginx日志报错bind()to80failed(13:Permissiondenied)时,这通常是由于权限不足导致Nginx无法绑定到80端口,下面就来... 目录一、问题原因分析二、解决方案1. 以 root 权限运行 Nginx(不推荐)2. 为 Nginx

解决1093 - You can‘t specify target table报错问题及原因分析

《解决1093-Youcan‘tspecifytargettable报错问题及原因分析》MySQL1093错误因UPDATE/DELETE语句的FROM子句直接引用目标表或嵌套子查询导致,... 目录报js错原因分析具体原因解决办法方法一:使用临时表方法二:使用JOIN方法三:使用EXISTS示例总结报错原

Windows环境下解决Matplotlib中文字体显示问题的详细教程

《Windows环境下解决Matplotlib中文字体显示问题的详细教程》本文详细介绍了在Windows下解决Matplotlib中文显示问题的方法,包括安装字体、更新缓存、配置文件设置及编码調整,并... 目录引言问题分析解决方案详解1. 检查系统已安装字体2. 手动添加中文字体(以SimHei为例)步骤

SpringSecurity整合redission序列化问题小结(最新整理)

《SpringSecurity整合redission序列化问题小结(最新整理)》文章详解SpringSecurity整合Redisson时的序列化问题,指出需排除官方Jackson依赖,通过自定义反序... 目录1. 前言2. Redission配置2.1 RedissonProperties2.2 Red

nginx 负载均衡配置及如何解决重复登录问题

《nginx负载均衡配置及如何解决重复登录问题》文章详解Nginx源码安装与Docker部署,介绍四层/七层代理区别及负载均衡策略,通过ip_hash解决重复登录问题,对nginx负载均衡配置及如何... 目录一:源码安装:1.配置编译参数2.编译3.编译安装 二,四层代理和七层代理区别1.二者混合使用举例

Java JDK1.8 安装和环境配置教程详解

《JavaJDK1.8安装和环境配置教程详解》文章简要介绍了JDK1.8的安装流程,包括官网下载对应系统版本、安装时选择非系统盘路径、配置JAVA_HOME、CLASSPATH和Path环境变量,... 目录1.下载JDK2.安装JDK3.配置环境变量4.检验JDK官网下载地址:Java Downloads

golang程序打包成脚本部署到Linux系统方式

《golang程序打包成脚本部署到Linux系统方式》Golang程序通过本地编译(设置GOOS为linux生成无后缀二进制文件),上传至Linux服务器后赋权执行,使用nohup命令实现后台运行,完... 目录本地编译golang程序上传Golang二进制文件到linux服务器总结本地编译Golang程序

使用Docker构建Python Flask程序的详细教程

《使用Docker构建PythonFlask程序的详细教程》在当今的软件开发领域,容器化技术正变得越来越流行,而Docker无疑是其中的佼佼者,本文我们就来聊聊如何使用Docker构建一个简单的Py... 目录引言一、准备工作二、创建 Flask 应用程序三、创建 dockerfile四、构建 Docker