为什么 QFile( "./test" ) 工作,尽管 [类 QFile] 没有 QFile(char* s) 构造函数
Why QFile("./test") work though [Class QFile] has no QFile(char* s) constructor
我检查了QT-Help,我发现类QFile
有以下构造函数:
QFile()
QFile(const QString &name)
QFile(QObject *parent)
QFile(const QString &name, QObject *parent)
对于QFile
类没有QFile(char *)
但是QFile("/home/mythicsr/test");
是可以的,为什么?
考虑以下语句:
QFile("/home/mythicsr/test");
它导致在底层创建QString
类型的临时对象,从而调用构造函数QFile(const QString &name)
。
正如@meetaig在评论中提到的,这是可能的,因为:
QString支持使用char*
初始化
或者更好,正如@Slava - const char *
在本例中所指出的那样。
。
相关文章:
- ArduinoJson 6.15.2:JsonObject没有命名类型
- 如果没有malloc,链表实现将失败
- 数组索引的值没有增加
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 在没有太多条件句的情况下,我如何避免被零除
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 变量没有改变?通过向量的函数调用
- 没有名称的C++模板参数
- 在线编译器中的分段C++没有打印消息
- 没有为自己的结构调用列表推回方法
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- 没有用于初始化C++中的变量模板的匹配构造函数
- 调用'begin(int [n])'没有匹配函数
- 使用C++程序合并排序没有得到正确的输出
- 为什么在这个代码结束循环中没有得到结束
- 有没有办法将谓词中的元素偏移量传递给 std 算法?
- Qt(C++):QFile成功创建了文本文件,但没有写入
- 为什么 QFile( "./test" ) 工作,尽管 [类 QFile] 没有 QFile(char* s) 构造函数