给错误screenshot.save('screenshot.png', 'PNG');
QT5 - 无法从 '诠释' 转换参数2“为const char *
..\screen\main.cpp(10): error C2015: too many characters in constant
..\screen\main.cpp(10): error C2664: 'bool QPixmap::save(QIODevice *,const char *,int) const': cannot convert argument 2 from 'int' to 'const char *'
代码:
#include "mainwindow.h"
#include <QApplication>
#include <QScreen>
#include <QPixmap>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QScreen *screen = a.primaryScreen();
QPixmap screenshot = screen->grabWindow(0);
screenshot.save('screenshot.png', 'PNG');
MainWindow w;
w.show();
return a.exec();
}
你必须使用'“'的字符串,而不是''' 。 – nwp
C++不是Python,不要假设,[学习它](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – Drop
[这解释](http: //en.cppreference.com/w/cpp/language/character_literal)int是从哪里来的。 – nwp