Qt Optional Argument没有匹配的函数调用

时间:2019-03-29 13:27:09

标签: c++ qt

当尝试使用定义为具有and选项参数的方法时,出现编译错误。错误消息是这样的:

  

错误:没有匹配的函数调用'ConsoleWidget :: logInfo(const   char [32])'consoleWidget-> logInfo(“这正在记录一条信息消息”);

下面是我的文件。

(标题)。h

{Android.Hardware.Camera2.CameraAccessException: Camera service is currently unavailable
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at Java.Interop.JniEnvironment+InstanceMethods.CallObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in <7802aa64ad574c33adca332a3fa9706a>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeAbstractObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00014] in <7802aa64ad574c33adca332a3fa9706a>:0 
  at Android.Hardware.Camera2.CameraManager.GetCameraCharacteristics (System.String cameraId) [0x00029] in <263adecfa58f4c449f1ff56156d886fd>:0 
  at TechnicianApp.Droid.Renderers.Camera.CameraDroid.OpenCamera () [0x0004e] in /Users/apple/Desktop/Pwc-Release/UATRelease3/technician-mobile-app/TechnicianApp.Android/Renders/Camera/CameraDroid.cs:96 
  --- End of managed Android.Hardware.Camera2.CameraAccessException stack trace ---
android.hardware.camera2.CameraAccessException: Camera service is currently unavailable
    at android.hardware.camera2.CameraManager.getCameraCharacteristics(CameraManager.java:192)
    at 

cpp(.cpp)

#ifndef CONSOLEWIDGET_H
#define CONSOLEWIDGET_H

#include <QTextEdit>
#include <QAction>
#include <QColor>

class ConsoleWidget : public QTextEdit
{
    Q_OBJECT
public:
    explicit ConsoleWidget(QWidget *parent = nullptr);

public slots:
    void logInfo(const QString& text, const bool includeTimestamp /*=false*/);
};

#endif // CONSOLEWIDGET_H

(主要).cpp

void ConsoleWidget::logInfo(const QString &text, bool includeTimestamp = false)
{
    ...
}

1 个答案:

答案 0 :(得分:0)

(默认)参数由函数的调用者评估并传递,因此必须知道在何处调用函数。

如果编译器已经看到

 void foo(int x = 37);

然后遇到

foo();

它将替换为等价

foo(37);

如果仅看到void foo(int x);,将不会有具有匹配原型的函数,因为函数始终都带有一个int参数。

(这与Python不同,例如,Python在定义函数且不需要关心调用代码时会评估默认参数)。

解决方案是将默认值从函数定义移至其声明。