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

相关文章

好题——hdu2522(小数问题:求1/n的第一个循环节)

好喜欢这题,第一次做小数问题,一开始真心没思路,然后参考了网上的一些资料。 知识点***********************************无限不循环小数即无理数,不能写作两整数之比*****************************(一开始没想到,小学没学好) 此题1/n肯定是一个有限循环小数,了解这些后就能做此题了。 按照除法的机制,用一个函数表示出来就可以了,代码如下

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu

JAVA智听未来一站式有声阅读平台听书系统小程序源码

智听未来,一站式有声阅读平台听书系统 🌟&nbsp;开篇:遇见未来,从“智听”开始 在这个快节奏的时代,你是否渴望在忙碌的间隙,找到一片属于自己的宁静角落?是否梦想着能随时随地,沉浸在知识的海洋,或是故事的奇幻世界里?今天,就让我带你一起探索“智听未来”——这一站式有声阅读平台听书系统,它正悄悄改变着我们的阅读方式,让未来触手可及! 📚&nbsp;第一站:海量资源,应有尽有 走进“智听

阿里开源语音识别SenseVoiceWindows环境部署

SenseVoice介绍 SenseVoice 专注于高精度多语言语音识别、情感辨识和音频事件检测多语言识别: 采用超过 40 万小时数据训练,支持超过 50 种语言,识别效果上优于 Whisper 模型。富文本识别:具备优秀的情感识别,能够在测试数据上达到和超过目前最佳情感识别模型的效果。支持声音事件检测能力,支持音乐、掌声、笑声、哭声、咳嗽、喷嚏等多种常见人机交互事件进行检测。高效推

购买磨轮平衡机时应该注意什么问题和技巧

在购买磨轮平衡机时,您应该注意以下几个关键点: 平衡精度 平衡精度是衡量平衡机性能的核心指标,直接影响到不平衡量的检测与校准的准确性,从而决定磨轮的振动和噪声水平。高精度的平衡机能显著减少振动和噪声,提高磨削加工的精度。 转速范围 宽广的转速范围意味着平衡机能够处理更多种类的磨轮,适应不同的工作条件和规格要求。 振动监测能力 振动监测能力是评估平衡机性能的重要因素。通过传感器实时监

安装nodejs环境

本文介绍了如何通过nvm(NodeVersionManager)安装和管理Node.js及npm的不同版本,包括下载安装脚本、检查版本并安装特定版本的方法。 1、安装nvm curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash 2、查看nvm版本 nvm --version 3、安装

缓存雪崩问题

缓存雪崩是缓存中大量key失效后当高并发到来时导致大量请求到数据库,瞬间耗尽数据库资源,导致数据库无法使用。 解决方案: 1、使用锁进行控制 2、对同一类型信息的key设置不同的过期时间 3、缓存预热 1. 什么是缓存雪崩 缓存雪崩是指在短时间内,大量缓存数据同时失效,导致所有请求直接涌向数据库,瞬间增加数据库的负载压力,可能导致数据库性能下降甚至崩溃。这种情况往往发生在缓存中大量 k

6.1.数据结构-c/c++堆详解下篇(堆排序,TopK问题)

上篇:6.1.数据结构-c/c++模拟实现堆上篇(向下,上调整算法,建堆,增删数据)-CSDN博客 本章重点 1.使用堆来完成堆排序 2.使用堆解决TopK问题 目录 一.堆排序 1.1 思路 1.2 代码 1.3 简单测试 二.TopK问题 2.1 思路(求最小): 2.2 C语言代码(手写堆) 2.3 C++代码(使用优先级队列 priority_queue)

【IPV6从入门到起飞】5-1 IPV6+Home Assistant(搭建基本环境)

【IPV6从入门到起飞】5-1 IPV6+Home Assistant #搭建基本环境 1 背景2 docker下载 hass3 创建容器4 浏览器访问 hass5 手机APP远程访问hass6 更多玩法 1 背景 既然电脑可以IPV6入站,手机流量可以访问IPV6网络的服务,为什么不在电脑搭建Home Assistant(hass),来控制你的设备呢?@智能家居 @万物互联

高并发环境中保持幂等性

在高并发环境中保持幂等性是一项重要的挑战。幂等性指的是无论操作执行多少次,其效果都是相同的。确保操作的幂等性可以避免重复执行带来的副作用。以下是一些保持幂等性的常用方法: 唯一标识符: 请求唯一标识:在每次请求中引入唯一标识符(如 UUID 或者生成的唯一 ID),在处理请求时,系统可以检查这个标识符是否已经处理过,如果是,则忽略重复请求。幂等键(Idempotency Key):客户端在每次