Calling an Objective-C class Function in C++ Class or main-window .widget so that the button, i have created using qt widget will use the objective-C Class method
I have one objective-C class which i have created in X-Code.
let say we call it ObjCClass: corresponding
@interface myClass : NSObject
NSLog (@"Hola Jitesh!!! you are inside Objective C Class");
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSString string = [formatter stringFromDate:date];
Now, I have one qt widget based project in which i have one button and one label. I want when i click on that button it will call ObjCClass method "doSomething" and and the result will show on label.
so in QT Creator i have:
button clicked method so what are the steps i need to follow to use that objective c method and include objective c class in qt project.
Hi and welcome to devnet,
First thing, rename your mywidget.cpp to mywidget.mm so the compiler will know that you are going write Objective-C++. Next, in your pro file add
OBJECTIVE_SOURCES += mywidget.mmand remove the corresponding mywidget.cpp
Now in mywidget.mm you can include your Objective-C class and use it in your C++ code. You can also take a look at the QtMacExtras module for some inspiration.
Hope it helps