Objective C++ and Qt



  • Hi,

    I would like to mix up objective C++ and Qt to work bluetooth in my mac desktop project. here is what I did for testing and it's not working. It's 'no sense code', but I would like to run it without errors:

    @
    //untitled.pro

    QT += core gui

    TARGET = untitled
    TEMPLATE = app

    SOURCES += main.cpp

    mac {
    OBJECTIVE_HEADERS += mainwindow.h

    OBJECTIVE_SOURCES += mainwindow.mm
    

    }

    //mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    class MainWindow{

    public:
    MainWindow();
    ~MainWindow();
    };

    #endif // MAINWINDOW_H

    //mainwindow.mm

    #include "mainwindow.h"
    #include <Foundation/Foundation.h>

    MainWindow::MainWindow()
    {
    NSString *s= @"string"; //if I take this line in a comment of corse it's working
    }

    MainWindow::~MainWindow()
    {

    }

    @

    Why it doesn't work?



  • You need to add this line to your .pro file:

    @
    LIBS += -framework Foundation
    @



  • really helpful, thank you Volker



  • If you're using Qt Creator, then unfortunately the error pane doesn't show that useful error messages. It's just a "symbol(s) not found" and "collect2: ld returned exit status 1". You should go to the compilation pane then, the error messages there are more elaborate.

    In your special case here, if you use a Mac framework, you will have to add it to the LIBS variable. Some of them are added by Qt by default, some need manual addition.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.