Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. 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

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

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 2 Posters 885 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jitesh
    wrote on 10 Apr 2015, 05:27 last edited by
    #1

    I have one objective-C class which i have created in X-Code.
    let say we call it ObjCClass: corresponding
    ObjCClass.h:
    #import <Foundation/Foundation.h>
    @interface myClass : NSObject
    -(NSString*) doSomething;
    @end
    ObjCClass.m:

    #include "ObjCFunc.h"
    @implementation myClass
    -(NSString*) doSomething
    {
    NSLog (@"Hola Jitesh!!! you are inside Objective C Class");
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy"];
    NSDate date;
    NSString
    string = [formatter stringFromDate:date];
    return string
    }
    @end

    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.
    Please help:-
    Thanks :):):)

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 10 Apr 2015, 22:13 last edited by
      #2

      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.mm and 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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      1/2

      10 Apr 2015, 05:27

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved