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. Qt Creator and iOS
Forum Updated to NodeBB v4.3 + New Features

Qt Creator and iOS

Scheduled Pinned Locked Moved Solved Mobile and Embedded
qt creatorios
17 Posts 2 Posters 6.5k Views 3 Watching
  • 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.
  • L Offline
    L Offline
    Leonardo
    wrote on last edited by
    #1

    Hi. I've been developing an app for Android, now I need to add support for iOS. I would like to keep using Qt Creator, so I can keep a single code base. I'm trying to mix C++ and Objective-C to use some native features or frameworks. I'm a little bit confused about the anatomy of a Qt app for iOS. I've been looking for some article like this one for Android

    https://blog.qt.io/blog/2013/07/23/anatomy-of-a-qt-5-for-android-application/

    but couldn't find anything. I'm also having trouble coding with Qt Creator. Let's say I have this code:

    #include <QtGui>
    #include <QtGui/5.5.0/QtGui/qpa/qplatformnativeinterface.h>
    
    #import <UIKit/UIKit.h>
    #import <FBSDKCoreKit/FBSDKCoreKit.h>
    #import <FBSDKLoginKit/FBSDKLoginKit.h>
    
    void MyController::facebookLogin(){
    
    	QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
    
    	UIView *view = static_cast<UIView *>(nativeInterface->nativeResourceForWindow("uiview", qApp->topLevelWindows().at(0)));
    
    	UIViewController *qtController = [[view window] rootViewController];
    
    	FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    	[login
    	  logInWithReadPermissions: @[@"public_profile",@"email"]
    			fromViewController: qtController
    					   handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
    	  if (error) {
    		NSLog(@"Process error");
    	  } else if (result.isCancelled) {
    		NSLog(@"Cancelled");
    	  } else {
    		NSLog(@"Logged in");
    	  }
    	}];
    
    }
    

    I can compile it, but Qt Creator puts a red underline on every Objective-C code. It cannot parse headers imported from Facebook SDK also.

    Is there any way to work with Objective-C on Qt Creator or should I move to XCode? In that case, how can I keep my XCode project synchronized with my .pro file?

    Thank you.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Since you are mixing both you're using Objective-C++ so is your file ending in mm ? Did you add it to OBJECTIVE_SOURCES in your pro file ?

      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
      • L Offline
        L Offline
        Leonardo
        wrote on last edited by
        #3

        Hi. Yes, I did. Here's part of my pro file:

        TEMPLATE = app
        
        QT += qml quick widgets
        
        SOURCES += mycontroller.cpp 
        HEADERS += mycontroller.h
        
        ios {
        
        	QMAKE_CXXFLAGS += -std=c++11 -stdlib=libc++ -F$$PWD/ios
        	QMAKE_LFLAGS += -stdlib=libc++ -F$$PWD/ios
        
        	OBJECTIVE_SOURCES += mycontroller_ios.mm
        
        	QMAKE_INFO_PLIST = ios/Info.plist
        
        	LIBS += -lz -framework UIKit -framework FBSDKCoreKit -framework FBSDKLoginKit
        
        }
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Where's the Facebook SDK located ?

          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
          • L Offline
            L Offline
            Leonardo
            wrote on last edited by
            #5

            Inside the ios folder. I already had a subfolder for the android tree, so I wanted to keep the pattern and created a subfolder for ios. As I said before, I can compile it, so I guess qmake is working properly.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Sorry, I may have misunderstood your problem. Did you mean that the you "only" have problem with auto-completion and such with Qt Creator ?

              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
              • L Offline
                L Offline
                Leonardo
                wrote on last edited by
                #7

                Yes. Check it out:

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by SGaist
                  #8

                  IIRC, you should rather have LIBS += -F $ $PWD/iOS (minus the spaces)

                  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
                  • L Offline
                    L Offline
                    Leonardo
                    wrote on last edited by
                    #9

                    Compilation works, but the editor still highlights Objective-C code... =(

                    ios {
                    
                    	QMAKE_CXXFLAGS += -std=c++11 -stdlib=libc++
                    	QMAKE_LFLAGS += -stdlib=libc++
                    
                    	OBJECTIVE_SOURCES += mycontroller_ios.mm
                    
                    	QMAKE_INFO_PLIST = ios/Info.plist
                    
                    	LIBS += -lz -F$$PWD/ios -framework UIKit -framework FBSDKCoreKit -framework FBSDKLoginKit
                    
                    }
                    
                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Did you try using the clang code model ?

                      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
                      • L Offline
                        L Offline
                        Leonardo
                        wrote on last edited by
                        #11

                        Hi. What do you mean by that?

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Qt Creator provides two code models (the beast that analyses your projects and provides all the nice stuff like auto-completion of your classes etc.) The default and the clang implementation that you can activate through the About Plugins menu.

                          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
                          • L Offline
                            L Offline
                            Leonardo
                            wrote on last edited by
                            #13

                            You nailed it!

                            For those interested:

                            http://doc.qt.io/qtcreator/creator-clang-codemodel.html

                            After enabling the plugin, go to

                            Preferences > C++ > Code Model

                            I changed both "Objective C" and "Objective C++" to clang. After that, the highlighting is gone.

                            It seems ok now. I can't test it properly, because I just upgraded to XCode 7 and broke Qt Creator's support for iOS, but it feels like to right solution.

                            Thank you.

                            1 Reply Last reply
                            1
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              What did break ?

                              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
                              • L Offline
                                L Offline
                                Leonardo
                                wrote on last edited by
                                #15

                                Apparently, Qt Creator is not compatible with XCode 7 toolchain. After upgrading, the compiler for iOS went missing.

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  What version of Qt Creator are you using ? IIRC Qt Creator 3.5.1 and Qt 5.5.1 don't suffer from that problem.

                                  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
                                  • L Offline
                                    L Offline
                                    Leonardo
                                    wrote on last edited by
                                    #17

                                    I'm using Qt 5.5.0 with Qt Creator 3.4.2. Maybe that's why, but I've already came to terms with using XCode. It works fine.

                                    Thank you.

                                    1 Reply Last reply
                                    0

                                    • Login

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