我正在尝试使用QDate以mmmm YYYY格式检索当前日期作为字符串。但是,我无法通过参数传递QDate :: currentDate。另一个问题是我传递的函数参数是QString,这意味着g ++会引发转换错误。如何绕过这个?
此处的代码:
QDate date = QDate::currentDate();
Core::MessageUser(this->CurrentEdit->User, warning, QString::number(date),
title, true, dependency);
编译器错误我经常得到的是这样的:
mainwindow.cpp: In member function 'bool Huggle::MainWindow::Warn(QString, Huggle::RevertQuery*)':
mainwindow.cpp:463:77: error: no matching function for call to 'QString::number(QDate&)'
Core::MessageUser(this->CurrentEdit->User, warning, QString::number(date),
^
mainwindow.cpp:463:77: note: candidates are:
In file included from /usr/include/qt5/QtCore/qobject.h:48:0,
from /usr/include/qt5/QtWidgets/qwidget.h:46,
from /usr/include/qt5/QtWidgets/qmainwindow.h:45,
from /usr/include/qt5/QtWidgets/QMainWindow:1,
from mainwindow.h:14,
from mainwindow.cpp:11:
/usr/include/qt5/QtCore/qstring.h:556:20: note: static QString QString::number(int, int)
static QString number(int, int base=10);
^
/usr/include/qt5/QtCore/qstring.h:556:20: note: no known conversion for argument 1 from 'QDate' to 'int'
/usr/include/qt5/QtCore/qstring.h:557:20: note: static QString QString::number(uint, int)
static QString number(uint, int base=10);
^
/usr/include/qt5/QtCore/qstring.h:557:20: note: no known conversion for argument 1 from 'QDate' to 'uint {aka unsigned int}'
/usr/include/qt5/QtCore/qstring.h:558:20: note: static QString QString::number(long int, int)
static QString number(long, int base=10);
^
/usr/include/qt5/QtCore/qstring.h:558:20: note: no known conversion for argument 1 from 'QDate' to 'long int'
/usr/include/qt5/QtCore/qstring.h:559:20: note: static QString QString::number(ulong, int)
static QString number(ulong, int base=10);
^
/usr/include/qt5/QtCore/qstring.h:559:20: note: no known conversion for argument 1 from 'QDate' to 'ulong {aka long unsigned int}'
/usr/include/qt5/QtCore/qstring.h:560:20: note: static QString QString::number(qlonglong, int)
static QString number(qlonglong, int base=10);
^
/usr/include/qt5/QtCore/qstring.h:560:20: note: no known conversion for argument 1 from 'QDate' to 'qlonglong {aka long long int}'
/usr/include/qt5/QtCore/qstring.h:561:20: note: static QString QString::number(qulonglong, int)
static QString number(qulonglong, int base=10);
^
/usr/include/qt5/QtCore/qstring.h:561:20: note: no known conversion for argument 1 from 'QDate' to 'qulonglong {aka long long unsigned int}'
/usr/include/qt5/QtCore/qstring.h:562:20: note: static QString QString::number(double, char, int)
static QString number(double, char f='g', int prec=6);
^
/usr/include/qt5/QtCore/qstring.h:562:20: note: no known conversion for argument 1 from 'QDate' to 'double'
make: *** [mainwindow.o] Error 1
答案 0 :(得分:0)
我想你需要打电话:
Core::MessageUser(this->CurrentEdit->User, warning, date.toString(),
title, true, dependency);
代替
<强>更新强>
如果您只需打印年份值:
Core::MessageUser(this->CurrentEdit->User, warning, QString::number(date.year()),
title, true, dependency);