QString在传递到功能时排空

QString empties while passing to function

本文关键字:功能 QString      更新时间:2023-10-16

我有一个用qt编写的项目。到目前为止,我在Windows中对其进行了测试,没有问题。今天,我尝试将其移植到Linux

我从qt.gitorius.org下载了QT源树。目前,它具有5.2.2版。它毫无问题地编译和安装。程序也没有问题进行编译。但是跑步时有一个问题。在调试时,我发现了奇怪的行为。不久的代码:

Config::Config()
{
    p_path = QApplication::applicationDirPath();
    if(!p_path.endsWith(QDir::separator())) p_path += QDir::separator();
    QString path = p_path + "Settings/config.xml";
    settings = new Settings(path,this); // here path is /opt/myprog/Settings/config.xml
}
Settings::Settings(const QString file, QObject * parent) : QObject(parent)
{
    p_file = file; // file is empty here!!!!   
    p_initialized = false;
    p_autosave = true;
    p_changed = false;
}

当我传递QString值以函数函数时,它会失去其值。

我在Windows中检查了相同的代码,并且它没有问题。

我的系统:

  • ubintu 13.10 64位
  • GCC 4.8.1
  • QT 5.2.2(git)

您显示的代码没有什么明显的错误,除了要将const 参考传递给字符串,但这不是问题的原因。Settings构造函数应具有以下签名:

Settings::Settings(const QString & file, QObject * parent)

您应该在项目上重新运行QMAKE,清洁和重建,然后重试。如果它仍然不起作用,那么您有一个内存错误,并且平台的更改只会在您的代码中揭示一个潜在错误。