給錯誤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