QString在传递到功能时排空
QString empties while passing to function
我有一个用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,清洁和重建,然后重试。如果它仍然不起作用,那么您有一个内存错误,并且平台的更改只会在您的代码中揭示一个潜在错误。
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 多态性和功能结合
- 将 Qvector<uint8_t> 转换为 QString
- 带内存和隔离功能的SQLite
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- 类模板的成员功能的定义在单独的TU中完全专业化
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 如何在C++中获得"静态纯虚拟"功能?
- 两个文件使用彼此的功能-如何解决
- 我应该实现右值推送功能吗?我应该使用std::move吗
- QML按钮点击功能执行顺序
- 无法理解此 return 语句的功能,没有它就会发生运行时错误
- 有没有可能有一个只有ADL才能找到的非好友功能
- 功能样式转换从 'int' 到 'ItemType' 的匹配转换
- 文件系统:复制功能的速度秘诀是什么
- 在用于格式4的arm模拟器中实现功能时的一个问题
- 如何在Directwrite中获得给定字体的可用OpenType功能
- 具有QList功能的QT应用程序<QString>"append"
- QString在传递到功能时排空
- 将变量或QString传递到插槽(function())C 中的功能