构造函数中Qt类型的C ++默认值

时间:2012-06-13 23:35:05

标签: c++ qt

我的标题中包含以下代码:

StripChartConfiguration(
    uint32_t tmpStripChartFrameworkWidgetWidth,
    uint32_t tmpStripChartFrameworkWidgetHeight,
    QString tmpMissionName,
    QList<QString> tmpCommandandToneNameQList,
    QList<QString> mToneNameQList,
    FTSProtocolType tmpMissionProtocol,
    float_t mStripHeightInPixels,
    float_t tmpTimeSliceWidth,
    uint32_t tmpTimeframeInSecondsPerStrip,
    QColor tmpStripChartGLViewportBackgroundColor
        = QColor(Qt::lightGray),
    QColor tmpDefaultStateSliceColor 
        = QColor(Qt::lightGray),
    QColor tmpCommandedStateSliceColor
        = QColor(Qt::darkBlue),
    QColor tmpRequestedStateSliceColor
        = QColor(Qt::darkMagenta),
    QColor tmpRequestedConfirmedStateSliceColor
        = QColor(Qt::darkGreen),
    QColor tmpConfirmedDefaultStateSliceColor
        = QColor(Qt::darkYellow),       
    QColor tmpSuspendedDefaultStateSliceColor
        = QColor(0x82B384), //Stale Green
    QColor tmpCarrierDefaultStateSliceColor
        = QColor(Qt::lightGray),
    QColor tmpCarrierCommandedStateSliceColor
        = QColor(Qt::blue),
    QColor tmpCarrierRequestedStateSliceColor
        = QColor(Qt::magenta),
    QColor tmpCarrierRequestedConfirmedStateSliceColor
        = QColor(Qt::green),
    QColor tmpCarrierConfirmedDefaultStateSliceColor
        = QColor(Qt::yellow),
    QColor tmpCarrierSuspendedDefaultStateSliceColor
        = QColor(0x82B384)); //Stale Green

现在我想要实例化这种类型的对象而不必指定颜色。所以从我的驱动程序中我做到了:

uint32_t mFWWidth = 800;
uint32_t mFWHeight = 600;
QString mMissionName("This Is A Mission");
QList<QString> mCommandNameList;
for (uint32_t i = 0; i < 10; ++i) {
    mCommandNameList.push_back(QString("Command"));
}
QList<QString> mToneNameList;
for (uint32_t i = 0; i < 6; ++i) {
    mToneNameList.push_back(QString("Tone"));
}
StripChartConfiguration::FTSProtocolType mSCCFTSProtocol =   
    StripChartConfiguration::Irig;
float_t mStripHeightInPixels = 10;
float_t mTimeSliceWidthInPixels = 10;
uint32_t mTimeframeInSecondsPerStrip = 15;
/*
 * End of list of configuration for strip chart
 */
StripChartConfiguration mSCCC(mFWWidth, mFWHeight,        
    mMissionName, mCommandNameList, mToneNameList,
    mSCCFTSProtocol, mStripHeightInPixels, 
    mTimeframeInSecondsPerStrip);

然而,g ++抱怨我错过了论点。我错过了什么?

mehoggan @ mehoggan:〜/ Dev / StripChart $ make

g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/opt/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/opt/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/opt/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/opt/QtSDK/Desktop/Qt/474/gcc/include/QtOpenGL -I/opt/QtSDK/Desktop/Qt/474/gcc/include -I/usr/X11R6/include -I. -o main.o main.cpp
main.cpp: In function ‘int main(int, char**)’:
main.cpp:39:36: error: no matching function for call to ‘StripChartConfiguration::StripChartConfiguration(uint32_t&, uint32_t&, QString&, QList<QString>&, QList<QString>&, StripChartConfiguration::FTSProtocolType&, float_t&, uint32_t&)’
main.cpp:39:36: note: candidates are:
stripchartconfiguration.h:84:5: note: StripChartConfiguration::StripChartConfiguration(const StripChartConfiguration&)
stripchartconfiguration.h:84:5: note:   candidate expects 1 argument, 8 provided
stripchartconfiguration.h:47:5: note: StripChartConfiguration::StripChartConfiguration(uint32_t, uint32_t, QString, QList<QString>, QList<QString>, StripChartConfiguration::FTSProtocolType, float_t, float_t, uint32_t, QColor, QColor, QColor, QColor, QColor, QColor, QColor, QColor, QColor, QColor, QColor, QColor, QColor)
stripchartconfiguration.h:47:5: note:   candidate expects 22 arguments, 8 provided
main.cpp:31:13: warning: unused variable ‘mTimeSliceWidthInPixels’ [-Wunused-variable]
make: *** [main.o] Error 1

1 个答案:

答案 0 :(得分:1)

您正在传递..., float_t&, uint32_t&),预计会..., float_t, float_t, uint32_t。你只是错过了一个浮动值。

请注意,您的代码样式看起来很糟糕。您不应该使用这么多参数创建构造函数和方法。很容易错过其中一个。显然它已经发生了。分别分配每个字段将更加清晰和安全。