[Solved]creat functions in mainwindow.cpp
-
wrote on 20 May 2014, 21:31 last edited by
Hello can someone please explain to me how to declare function if I need calculate something .
@int test(int a,int b){
int c;
c=a*b;
return c;
}void MainWindow::on_pushButton_clicked() {
int aa=4;
int bb=0;
int cc=0;
cc=test(aa,bb); } @ -
wrote on 20 May 2014, 21:47 last edited by
Your example looks ok.
I would declare test() as part of MainWindow but in general it looks ok.
What is wrong with your code now? -
wrote on 20 May 2014, 22:14 last edited by
I get this error :
S:\C&C++ programing\QT\MASTER\MASTER-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug..\MASTER\mainwindow.cpp:160: ошибка: 'test' was not declared in this scope -
wrote on 20 May 2014, 23:35 last edited by
Is function test() defined in mainwindow.cpp?
Is it defined before first use?If not then you need to declare it before first use.
- mainwindow.cpp
@
int test(int, int); // <-- this is a declaration
void MainWindow::on_pushButton_clicked()
{
int aa=4;
int bb=0;
int cc=0;
cc=test(aa,bb);
}int test(int a,int b)
{
int c;
c=a*b;
return c;
}
@ - mainwindow.cpp
-
wrote on 21 May 2014, 15:49 last edited by
Thank you this was my problem. :)
1/5