c++ - Call a function when button clicked in QT -


i have seen similar questions mine on here, still having issues.

i have button in qt, have function defined in main.cpp file. when push qt button want call function in main.cpp , let function thing.

mainwindow.cpp:

void mainwindow::on_startmotor_clicked() {     sendcmd(100); } 

main.cpp:

void sendcmd(int value) { } 

but error:

error: 'sendcmd' not declared in scope      sendcmd(100);                                              ^ 

im new qt dont think understand slots , signals thing.

thanks!

this not issue qt basic c++. general recommendation, therefore, buy book , learn language beginning @ basics.

in particular setting, have 2 cpp files. in context, called translation units because each of these files compiled separately. result of so-called object files (.obj). linker has job make functions of 1 object file known other file.

now, linker can job if translation units know of declarations of functions of other translation units.

usually, have header file contains declaration.

main.h:

void sendcmd(int value); // type int way? 

now, both main.cpp , mainwindow.cpp should include file. way, not compiler error because mainwindow.cpp has declaration of function call. , since main.cpp compiled, linker has implementation of function in repository of functions , can let mainwindow.cpp know it.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -