D:\Qt\qextserialport-1.2win-alpha\examples\qespta\MessageWindow.cpp:88: error: 'class QString' has no member named 'toAscii' fprintf(stderr, MessageWindow::QtMsgToQString(type, msg).toAscii()); ^~~~~~~
时间: 2023-12-06 18:45:22 浏览: 34
这个错误是因为在较新版本的 Qt 中,`toAscii()` 方法已经被弃用并且从 QString 类中移除了。你可以尝试使用 `toLatin1()` 或者 `toUtf8()` 方法来代替。
修改方法:
将该行代码修改为:
```
fprintf(stderr, MessageWindow::QtMsgToQString(type, msg).toUtf8());
```
或者
```
fprintf(stderr, MessageWindow::QtMsgToQString(type, msg).toLatin1());
```
这样应该就能解决这个错误了。
相关问题
:-1: error: No rule to make target '../../Qt/qextserialport-1.2win-alpha/examples/qespta/main.cpp', needed by 'main.o'. Stop.
这个错误通常表示Makefile中缺少了编译main.cpp的规则。你可以检查Makefile文件中是否包含了main.cpp的编译规则,或者在Makefile中添加以下规则:
```
main.o: ../../Qt/qextserialport-1.2win-alpha/examples/qespta/main.cpp
$(CC) $(CFLAGS) -c $< -o $@
```
其中,`$(CC)`是你使用的编译器,`$(CFLAGS)`是编译器的参数,`$<`表示依赖的源文件,`$@`表示生成的目标文件。你需要根据实际情况修改这些参数。
C:\Qt\Examples\Qt-6.6.1\demos\documentviewer\app\mainwindow.cpp:128: error: Calling a private constructor of class 'QString'
在C++中,QString类的构造函数是私有的,这意味着不能直接调用私有构造函数来创建QString对象。私有构造函数通常用于实现单例模式或其他特定的设计模式。
在你提供的错误信息中,出现了一个尝试调用私有构造函数的错误。这可能是因为在代码中尝试直接调用了QString的私有构造函数,而不是使用公共的构造函数来创建QString对象。
要解决这个错误,你需要检查代码中是否有直接调用QString私有构造函数的地方,并将其替换为使用公共的构造函数来创建QString对象。
如果你能提供更多的代码或上下文信息,我可以给出更具体的建议。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)