I'm trying to call a user-defined function while clicking a button.Here's my code and the error I'm getting
Here's my .h file
#include <QApplication>
#include <QPushButton>
#include <QGridLayout>
#include <QLCDNumber>
#include <QString>
#include <iostream>
#include <test.h>
int i;
int calc::appendone()
{
i = 1;
str.append("1");
return 0;
}
int main(int argc, char *argv[])
{
QObject::connect(one,
SIGNAL(clicked
()),
&calc,
SLOT(appendone
()));
std::cout<<i;
if(i == 1)
{
str.append("1");
lcd->display(str);
}
lcd->display(str);
layout->addWidget(zero,5,1);
layout->addWidget(equ,5,3);
layout->addWidget(one,4, 2);
layout->addWidget(two,4,1);
layout->addWidget(three,4,0);
layout->addWidget(add,4,3);
layout->addWidget(sub,4,4);
layout->addWidget(four,3,2);
layout->addWidget(five,3,1);
layout->addWidget(six,3,0);
layout->addWidget(mul,5,3);
layout->addWidget(div,5,4);
layout->addWidget(seven,2,2);
layout->addWidget(eight,2,1);
layout->addWidget(nine,2,0);
layout->addWidget(lcd,2,3);
window->setLayout(layout);
window->show();
return app.exec();
}
#include <QApplication>
#include <QPushButton>
#include <QGridLayout>
#include <QLCDNumber>
#include <QString>
#include <iostream>
#include <test.h>
int i;
QString str = "0";
int calc::appendone()
{
i = 1;
str.append("1");
return 0;
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *window = new QWidget;
QPushButton *one = new QPushButton("1");
QPushButton *two = new QPushButton("2");
QPushButton *three = new QPushButton("3");
QPushButton *four = new QPushButton("4");
QPushButton *five = new QPushButton("5");
QPushButton *six = new QPushButton("6");
QPushButton *seven = new QPushButton("7");
QPushButton *eight = new QPushButton("8");
QPushButton *nine = new QPushButton("9");
QPushButton *zero = new QPushButton("0");
QPushButton *add = new QPushButton("+");
QPushButton *sub = new QPushButton("-");
QPushButton *mul = new QPushButton("*");
QPushButton *div = new QPushButton("/");
QPushButton *equ = new QPushButton("=");
QLCDNumber *lcd = new QLCDNumber(5);
QObject::connect(one, SIGNAL(clicked()), &calc, SLOT(appendone()));
std::cout<<i;
if(i == 1)
{
str.append("1");
lcd->display(str);
}
QGridLayout *layout = new QGridLayout;
lcd->display(str);
layout->addWidget(zero,5,1);
layout->addWidget(equ,5,3);
layout->addWidget(one,4, 2);
layout->addWidget(two,4,1);
layout->addWidget(three,4,0);
layout->addWidget(add,4,3);
layout->addWidget(sub,4,4);
layout->addWidget(four,3,2);
layout->addWidget(five,3,1);
layout->addWidget(six,3,0);
layout->addWidget(mul,5,3);
layout->addWidget(div,5,4);
layout->addWidget(seven,2,2);
layout->addWidget(eight,2,1);
layout->addWidget(nine,2,0);
layout->addWidget(lcd,2,3);
window->setLayout(layout);
window->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
My .CPP file
#include <QApplication>
#include <QPushButton>
#include <QGridLayout>
#include <QLCDNumber>
#include <QString>
#include <iostream>
#include <test.h>
int i;
int calc::appendone()
{
i = 1;
str.append("1");
return 0;
}
int main(int argc, char *argv[])
{
QObject::connect(one,
SIGNAL(clicked
()),
&calc,
SLOT(appendone
()));
//line 37 std::cout<<i;
if(i == 1)
{
str.append("1");
lcd->display(str);
}
lcd->display(str);
layout->addWidget(zero,5,1);
layout->addWidget(equ,5,3);
layout->addWidget(one,4, 2);
layout->addWidget(two,4,1);
layout->addWidget(three,4,0);
layout->addWidget(add,4,3);
layout->addWidget(sub,4,4);
layout->addWidget(four,3,2);
layout->addWidget(five,3,1);
layout->addWidget(six,3,0);
layout->addWidget(mul,5,3);
layout->addWidget(div,5,4);
layout->addWidget(seven,2,2);
layout->addWidget(eight,2,1);
layout->addWidget(nine,2,0);
layout->addWidget(lcd,2,3);
window->setLayout(layout);
window->show();
return app.exec();
}
#include <QApplication>
#include <QPushButton>
#include <QGridLayout>
#include <QLCDNumber>
#include <QString>
#include <iostream>
#include <test.h>
int i;
QString str = "0";
int calc::appendone()
{
i = 1;
str.append("1");
return 0;
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *window = new QWidget;
QPushButton *one = new QPushButton("1");
QPushButton *two = new QPushButton("2");
QPushButton *three = new QPushButton("3");
QPushButton *four = new QPushButton("4");
QPushButton *five = new QPushButton("5");
QPushButton *six = new QPushButton("6");
QPushButton *seven = new QPushButton("7");
QPushButton *eight = new QPushButton("8");
QPushButton *nine = new QPushButton("9");
QPushButton *zero = new QPushButton("0");
QPushButton *add = new QPushButton("+");
QPushButton *sub = new QPushButton("-");
QPushButton *mul = new QPushButton("*");
QPushButton *div = new QPushButton("/");
QPushButton *equ = new QPushButton("=");
QLCDNumber *lcd = new QLCDNumber(5);
QObject::connect(one, SIGNAL(clicked()), &calc, SLOT(appendone())); //line 37
std::cout<<i;
if(i == 1)
{
str.append("1");
lcd->display(str);
}
QGridLayout *layout = new QGridLayout;
lcd->display(str);
layout->addWidget(zero,5,1);
layout->addWidget(equ,5,3);
layout->addWidget(one,4, 2);
layout->addWidget(two,4,1);
layout->addWidget(three,4,0);
layout->addWidget(add,4,3);
layout->addWidget(sub,4,4);
layout->addWidget(four,3,2);
layout->addWidget(five,3,1);
layout->addWidget(six,3,0);
layout->addWidget(mul,5,3);
layout->addWidget(div,5,4);
layout->addWidget(seven,2,2);
layout->addWidget(eight,2,1);
layout->addWidget(nine,2,0);
layout->addWidget(lcd,2,3);
window->setLayout(layout);
window->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Here's the error I'm getting
test.cpp: In function ‘int main(int, char**)’:
test.cpp:37:45: error: expected primary-expression before ‘,’ token
test.cpp: In function ‘int main(int, char**)’:
test.cpp:37:45: error: expected primary-expression before ‘,’ token
To copy to clipboard, switch view to plain text mode
Thanks in advance
Bookmarks