current position:Home>[Qt] About using the file path in QtCreator to report an error unknown escape sequence '\p' problem explanation

[Qt] About using the file path in QtCreator to report an error unknown escape sequence '\p' problem explanation

2022-11-24 23:07:52Evenurs

1. Phenomena

In Qt, a certain file path needs to be opened, and the pop-up warning cannot be opened normally through the CV copy and paste method of windows.



void MainWindow::paintEvent(QPaintEvent *){QPainter painter(this);QPixmap pix;pix.load(_IMG_DISK);painter.drawPixmap(_DISK_X,_DISK_Y,_DISK_W*_COOR_COE,_DISK_H*_COOR_COE,pix);painter.translate(_DISK_W/2*_COOR_COE,_DISK_H/2*_COOR_COE);pix.load(_IMG_HOUR);painter.rotate(CT.GetAngleHour());painter.drawPixmap((_HOUR_X-_DISK_W/2)*_COOR_COE,(_HOUR_Y-_DISK_H/2)*_COOR_COE,_HOUR_W*_COOR_COE,_HOUR_H*_COOR_COE,pix);pix.load(_IMG_MIN);painter.rotate(CT.GetAngleMinute()-CT.GetAngleHour());painter.drawPixmap((_MINU_X-_DISK_W/2)*_COOR_COE,(_MINU_Y-_DISK_H/2)*_COOR_COE,_MINU_W*_COOR_COE,_MINU_H*_COOR_COE,pix);pix.load(_IMG_SEC);painter.rotate(CT.GetAngleSecond()-CT.GetAngleMinute());painter.drawPixmap((_SECO_X-_DISK_W/2)*_COOR_COE,(_SECO_Y-_DISK_H/2)*_COOR_COE,_SECO_W*_COOR_COE,_SECO_H*_COOR_COE,pix);}

2. Reason

2.1 Macro definition

Macro definition warning, here you need to open several dial and pointer png files to draw a virtual dial example.

A macro is defined as follows:


#define _IMG_DISK "E:\program\qt\timer\disk.png"#define _IMG_HOUR "E:\program\qt\timer\hour.png"#define _IMG_MIN "E:\program\qt\timer\minute.png"#define _IMG_SEC "E:\program\qt\timer\second.png"

Macro definitions do not have any actual warnings.

2.2 path

This path is copied from:

2.3 Path format

Paths are usually separated by slashes '/' and backslashes '\'.What is copied in Windows is the backslash, including but not limited to the fopen file opening function in c, separated by slashes in web pages or other paths, so try to change the backslash here.

3. Effect

The changes are as follows:

#define _IMG_DISK "E:/program/qt/timer/disk.png"#define _IMG_HOUR "E:/program/qt/timer/hour.png"#define _IMG_MIN "E:/program/qt/timer/minute.png"#define _IMG_SEC "E:/program/qt/timer/second.png"

The operation effect is as follows:

Problem solved.

Four. Summary

Nothing to remember, Qt uses slashes to separate paths...

copyright notice
author[Evenurs],Please bring the original link to reprint, thank you.

Random recommended