Access to cpp variable from objective c .mm file in qt
-
wrote on 11 Oct 2014, 09:06 last edited by
I've used a .mm file in my qt creator to implement an ios application. I've declared a cpp method in header file and i've implemented it on .mm file.then in cpp file implementation, i've called an objective-c method for fetching addressbook.
@
//.mm file
@interface MyObject :NSObject
{
…
}
-(int)doSomethingWith:(void *) aParam;
@end@implementation MyObject
int MainWindow::MyCPPMethod(void *self, void * aParam)
{
self = [[MyObject alloc] init];
return [(id) self doSomethingWith:aParam];
}-(int)doSomethingWith:(void *) aParam
{
NSLog(@“Result: %d” , 21);
return 21;
}
@end//
@Everything is right, but i want to use some objective-c variable in cpp side (mainwindow class). how can i share a variable between cpp class and objective-c class in qt?
Thanks[edit: added missing coding tags @ SGaist]
-
Hi,
Have a look at the QtMacExtras module. It implements that technique
-
wrote on 11 Oct 2014, 09:36 last edited by
Thanks for your help, but i want something like this:
- fetch contacts names from ios addressbook( with objective-c code in .mm file)
- save each contact name in an array like QString name[] ( the array is defined in a cpp class)
how can do that?
If i define the array in cpp header file, it is not recognized in .mm file.
-
Don't create an array of QString, just a QStringList, it will make your life easier. Also don't try to share variables like that especially if you are just trying to access some data.
Follow the code of badgeLabelText in qmacfunctions.h/qmacfunctions_mac.mm
1/4