Search code examples
qtqspinboxqapplication

Qt creator vs 2013 (error c1057)


iam trying to build this program but it give me c1057 fatal error . When i removed connect function (line 15) it worked well and i don't know the reason this is the message : C:\Users\Ahmed\Documents\Qt-App\SpinnerAndSliders\main.cpp:15: error: C1057: unexpected end of file in macro expansion

#include <QSpinBox>
#include <QSlider>
#include <QApplication>
#include <QHBoxLayout>
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QWidget *mainWindow = new QWidget();
    mainWindow -> setWindowTitle("Sound volume");
    QSpinBox *spinner = new QSpinBox();
    QSlider *slider = new QSlider(Qt::Horizontal) ;
    QHBoxLayout *layout = new QHBoxLayout  ;
    spinner -> setRange(0,50);
    slider -> setRange(0,50);
    QObject::connect(spinner,SIGNAL(valueChanged(int),slider , SLOT(setValue(int));
    layout -> addWidget(spinner);
    layout -> addWidget(slider);
    spinner->setValue(10);
    mainWindow -> setLayout(layout);
    mainWindow -> show();
    return app.exec();
}

Solution

  • Your parentheses are out of match on your connect statement.

    Change your line to:

    QObject::connect(spinner,SIGNAL(valueChanged(int)),slider , SLOT(setValue(int)));

    and that should take care of you.

    When QtCreator autocompletes on connect statements, it often does not add an ending parenthesis. It has caught me a number of times.