Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. How to merge cocoa into Qt?

How to merge cocoa into Qt?

Scheduled Pinned Locked Moved Language Bindings
6 Posts 2 Posters 7.8k 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.
  • N Offline
    N Offline
    neha1
    wrote on 3 May 2011, 10:34 last edited by
    #1

    Hi

    I am working on Qt4.7 on mac os 10.5.8, i want to develop an application in which i have to merge Cocoa code , i have heard that it is possible to merge cocoa with Qt. Can you provide me an example that how can i integrate cocoa classes(.m,.h and .xib) with Qt. How can i make the object of (.xib) file and call it through my Qt application.

    Regards,
    neha

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on 3 May 2011, 11:00 last edited by
      #2

      There are OBJECTIVE_HEADERS and OBJECTIVE_SOURCES variables to qmake (though undocumente), you can use those in order to include your Objective-C sources into your Qt project.

      To put the .xib file into the right place in the application bundle, have a look at the wiki article "How to add resource files to an OS X application bundle":http://developer.qt.nokia.com/wiki/Resource_files_in_OS_X_bundle, just adapt the variable names etc.

      To call Cocoa stuff in your regular C++ code: Just go ahead, you can happily mix them. See http://el-tramo.be/blog/mixing-cocoa-and-qt for an example or have a look at the Qt sources, the Trolls are using Cocoa themselves of course :)

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • N Offline
        N Offline
        neha1
        wrote on 3 May 2011, 11:29 last edited by
        #3

        Thanks for the reply, i have some doubt, i had a cocoa application in which (MainMenu.xib) file is launched on application load, and in cocoa application it is called in its bq. main.m class like this:

        @#import <Cocoa/Cocoa.h>

        int main(int argc, char *argv[])
        {
        return NSApplicationMain(argc, (const char **) argv);
        }
        @

        How can i call this (MainMenu.xib) file using Qt in my main.cpp at application launch.

        and

        bq. To put the .xib file into the right place in the application bundle, have a look at the wiki article

        but in this there is an example to add qml file:

        you can let qmake do all the copy work for you. Just add a snippet like this to your .pro file:

        bq. APP_QML_FILES.files = path/to/file1.qml path/to/file2.qml
        APP_QML_FILES.path = Contents/Resources
        QMAKE_BUNDLE_DATA += APP_QML_FILES

        is this the same way to add .xib file of cocoa.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on 3 May 2011, 11:42 last edited by
          #4

          For the application:
          I'm not sure you can have a NSApplicationMain and a QApplication simultaneously, I'm pretty sure you cannot (as NSApplicationMain seem to block until the application ends, which is the same as QApplication's exec).

          You can use alien (native) widgets together with Qt, though. Have a look at the "Alien widgets on Mac":http://labs.qt.nokia.com/2011/02/23/alien-widgets-on-mac/ blog entry on Qt Labs.

          For the other way round (using Qt widgets in native Mac), have a look at "QMacNativeWidget":http://doc.qt.nokia.com/latest/qmacnativewidget.html

          It's unclear what you're trying to do so far.

          For copying the .xib:
          The snippet is ok, just replace the paths with yours and replace QML with XIB, if you want. It's just names, no special meanings. The only constraint is, you must be consistent and use the same variable name :)

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • N Offline
            N Offline
            neha1
            wrote on 3 May 2011, 12:06 last edited by
            #5

            Thanks for the reply, actually i am trying to show MainMenu.xib file at application launch, but i didnt get it how can i do this by using Qt QApplication.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on 3 May 2011, 12:42 last edited by
              #6

              I never worked with native Cocoa/XIB files, so I cannot comment on this one. I would dig deeper into the alien widgets topic, though. Maybe "QMacCocoaViewContainer":http://doc.qt.nokia.com/latest/qmaccocoaviewcontainer.html can be of help for you here. It contains an example for including a NSSearchField into a Qt widget.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0

              6/6

              3 May 2011, 12:42

              • Login

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