Afif Grahaditya(deleted)
02/08/2016 11:05 PM
post115696
|
are you sure you can use C++ in photon GUI?? I thought you can only use C in photon GUI. that's why the format of
callback is .c (format for C in momentics) not .cc (format for C++ in momentics)
|
|
|
Thomas Haupt
02/09/2016 6:07 AM
post115699
|
Hi Pawel (sorry, missing the correct key on my keyboard...),
I assume your problems originate in PhAB (the Photon Application Builder tool) not originally knowing that you intend to
make a C++ application. As you probably have already noticed, PhAB will create a number of source files for you. It
also creates "stubs" functions for callbacks you defined for different widgets. It is important (or at least, easiest)
if PhAB can know you want to do C++ _before it generates all the code for the first time_.
The easiest way to do so is by telling PhAB to place the stub functions in files with the suffix ".cc". PhAB will
automatically recognize this and generate (almost all) the rest accordingly. It will even generate an "abmain.cc"
instead of "abmain.c".
When defining callback (or other) functions in PhAB, you can use different special notations. They are documented under:
http://www.qnx.com/developers/docs/6.5.0SP1.update/index.html#./com.qnx.doc.photon_prog_guide/code.html#
FunctionFileNames
So assume you have a button widget and add an "activate" callback, then...
- naming the callback "btn_act@cb.cc" will add a C callback stub "btn_act()" to "cb.cc" and create the file if
necessary
- naming the callback "btn::act@cb.cc" will add a stub member function "btn::act()" to "cb.cc" and create the file if
necessary
...
All of these methods will tell PhAB that you're planning to do C++, and let it act appropriately.
There's one potential problem, though -- PhAB will (by default) also try to auto-generate a file named "proto.h" with
prototypes of all non-static functions in your project. The prototype generator is not C++-aware, which will likely
cause your class methods to appear in "proto.h" and cause compiler errors in various source files. I usually opt to
disable prototype generation and manage the prototyping manually. To disable auto-prototyping, open the "Project" menu
in PhAB and select "Properties". In the "Project Properties" dialog, go to the "Generate Options" tab and un-check "Scan
Source Files for Prototypes".
Attached is a small example project that uses a class "ball_c" to manage an arbitrary number of balls moving across the
window and can be added/deleted on the fly. Hope this helps a bit.
Kind regards,
Thomas
|
|
|