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

相关文章

Nginx启动失败:端口80被占用问题的解决方案

《Nginx启动失败:端口80被占用问题的解决方案》在Linux服务器上部署Nginx时,可能会遇到Nginx启动失败的情况,尤其是错误提示bind()to0.0.0.0:80failed,这种问题通... 目录引言问题描述问题分析解决方案1. 检查占用端口 80 的进程使用 netstat 命令使用 ss

mybatis和mybatis-plus设置值为null不起作用问题及解决

《mybatis和mybatis-plus设置值为null不起作用问题及解决》Mybatis-Plus的FieldStrategy主要用于控制新增、更新和查询时对空值的处理策略,通过配置不同的策略类型... 目录MyBATis-plusFieldStrategy作用FieldStrategy类型每种策略的作

linux下多个硬盘划分到同一挂载点问题

《linux下多个硬盘划分到同一挂载点问题》在Linux系统中,将多个硬盘划分到同一挂载点需要通过逻辑卷管理(LVM)来实现,首先,需要将物理存储设备(如硬盘分区)创建为物理卷,然后,将这些物理卷组成... 目录linux下多个硬盘划分到同一挂载点需要明确的几个概念硬盘插上默认的是非lvm总结Linux下多

Python Jupyter Notebook导包报错问题及解决

《PythonJupyterNotebook导包报错问题及解决》在conda环境中安装包后,JupyterNotebook导入时出现ImportError,可能是由于包版本不对应或版本太高,解决方... 目录问题解决方法重新安装Jupyter NoteBook 更改Kernel总结问题在conda上安装了

pip install jupyterlab失败的原因问题及探索

《pipinstalljupyterlab失败的原因问题及探索》在学习Yolo模型时,尝试安装JupyterLab但遇到错误,错误提示缺少Rust和Cargo编译环境,因为pywinpty包需要它... 目录背景问题解决方案总结背景最近在学习Yolo模型,然后其中要下载jupyter(有点LSVmu像一个

解决jupyterLab打开后出现Config option `template_path`not recognized by `ExporterCollapsibleHeadings`问题

《解决jupyterLab打开后出现Configoption`template_path`notrecognizedby`ExporterCollapsibleHeadings`问题》在Ju... 目录jupyterLab打开后出现“templandroidate_path”相关问题这是 tensorflo

如何解决Pycharm编辑内容时有光标的问题

《如何解决Pycharm编辑内容时有光标的问题》文章介绍了如何在PyCharm中配置VimEmulator插件,包括检查插件是否已安装、下载插件以及安装IdeaVim插件的步骤... 目录Pycharm编辑内容时有光标1.如果Vim Emulator前面有对勾2.www.chinasem.cn如果tools工

在MySQL执行UPDATE语句时遇到的错误1175的解决方案

《在MySQL执行UPDATE语句时遇到的错误1175的解决方案》MySQL安全更新模式(SafeUpdateMode)限制了UPDATE和DELETE操作,要求使用WHERE子句时必须基于主键或索引... mysql 中遇到的 Error Code: 1175 是由于启用了 安全更新模式(Safe Upd

最长公共子序列问题的深度分析与Java实现方式

《最长公共子序列问题的深度分析与Java实现方式》本文详细介绍了最长公共子序列(LCS)问题,包括其概念、暴力解法、动态规划解法,并提供了Java代码实现,暴力解法虽然简单,但在大数据处理中效率较低,... 目录最长公共子序列问题概述问题理解与示例分析暴力解法思路与示例代码动态规划解法DP 表的构建与意义动

Java多线程父线程向子线程传值问题及解决

《Java多线程父线程向子线程传值问题及解决》文章总结了5种解决父子之间数据传递困扰的解决方案,包括ThreadLocal+TaskDecorator、UserUtils、CustomTaskDeco... 目录1 背景2 ThreadLocal+TaskDecorator3 RequestContextH