How to use QtMacExtras to get a unified toolbar on Mac



  • Calling QMainWindow::setUnifiedTitleAndToolBarOnMac has no effect on Qt 5. A replacement API which wraps NSToolbar is available in QtMacExtras. I just wanna a demo, so I can learn it.



  • In order to use QtMacExtras you need to pull the code from Gitorius, compile it, add the MacExtras libraries to your Qt installation. Then you can compile the examples provided with the MacExtras code. To do that (assuming you run Qt Creator 2.7) you need to:

    Choose File|New File or Project...

    In the 'Choose Template' dialogue choose 'Import Project', then 'Gitorius Repository Clone'. Hit 'Choose' button.

    In the host list select 'gitorius.org' and click 'Continue'.

    In the 'Project' dialogue select 'Qt' (there are thousands of projects, and by default the list is dynamically updated, so you might not see it immediately; you may want to use the filter on top to narrow down the list). Click 'Continue'.

    In the 'Repository' dialogue select 'qtmacextras' (you may want to use filter again). Click 'Continue'.

    In the following dialogue, choose the check-out folder (where you want your copy installed). Click 'Continue'.

    Qt Creator will download the project and open the configuration page.

    Now you can go ahead and build the qtmacextras.pro, but to actually use it, you need to install it. I did it with a 'make install' terminal command issued in the build folder of the project (though you could also do it manually).

    Once mac extras are installed, you can open and compile the included example projects to play with them. Note that the functionality of QMacNativeToolBar as it stands now is quite limited.

    Hope it helps.



  • thanks a lot, but could you tell me more about how to install it, I 've succeeded at the above 7 steps, but when I build the project, it comes some errors. I really don't know how to install it, would you describe it like the above 7 steps. thanks again.
    [quote author="Skh1002" date="1369938418"]In order to use QtMacExtras you need to pull the code from Gitorius, compile it, add the MacExtras libraries to your Qt installation. Then you can compile the examples provided with the MacExtras code. To do that (assuming you run Qt Creator 2.7) you need to:

    Choose File|New File or Project...

    In the 'Choose Template' dialogue choose 'Import Project', then 'Gitorius Repository Clone'. Hit 'Choose' button.

    In the host list select 'gitorius.org' and click 'Continue'.

    In the 'Project' dialogue select 'Qt' (there are thousands of projects, and by default the list is dynamically updated, so you might not see it immediately; you may want to use the filter on top to narrow down the list). Click 'Continue'.

    In the 'Repository' dialogue select 'qtmacextras' (you may want to use filter again). Click 'Continue'.

    In the following dialogue, choose the check-out folder (where you want your copy installed). Click 'Continue'.

    Qt Creator will download the project and open the configuration page.

    Now you can go ahead and build the qtmacextras.pro, but to actually use it, you need to install it. I did it with a 'make install' terminal command issued in the build folder of the project (though you could also do it manually).

    Once mac extras are installed, you can open and compile the included example projects to play with them. Note that the functionality of QMacNativeToolBar as it stands now is quite limited.

    Hope it helps.[/quote]



  • Well, I can't assist without the details about errors you are getting and steps you are taking. Please, when looking for help, don't expect people to ask for basic information (few would be patient enough to do so). At the minimum, you should specify exactly what you were doing and what kind of errors you saw.

    After pulling the qt-macextras code and configuring the project, you should have 'qtmacextras' as your active project. At this point you should be able to hit Cmd+B and build it. There will be some warnings, but they can be safely disregarded.

    I have just tried building Mac Extras on a standard installation of both Qt 5.1.0 beta and Qt 5.0.2. Everything works as expected. However, if you already have Mac Extras libraries/modules installed into Qt 5.0.2 you might get some errors about the file 'qt_lib_macextras.pri' not being found. I have not investigated why that happens. On a fresh Qt installation there should not be any problems.

    Edit: I am using Mac OS X 10.8.2, I had no experience with building Mac Extras on other OS versions.



  • I got also many error when I tried to build QtMacExtras. I downloaded source code and open qtmacextras.pro to QtCreator. Then Build -> Build project "qtmacextras". I got the following errors:

    @In file included from /Users/user/Desktop/qt-qtmacextras/src/macextras/qmacnativetoolbar.mm:44:
    /Users/user/Desktop/qt-qtmacextras/src/macextras/qmactoolbardelegate.h:84:1: error: unknown type name 'QT_NAMESPACE_ALIAS_OBJC_CLASS'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacToolbarDelegate);
    In file included from /Users/user/Desktop/qt-qtmacextras/src/macextras/qmacnativetoolbar.mm:45:
    /Users/user/Desktop/qt-qtmacextras/src/macextras/qnstoolbar.h:60:1: error: unknown type name 'QT_NAMESPACE_ALIAS_OBJC_CLASS'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QtNSToolbar);
    /Users/user/Desktop/qt-qtmacextras/src/macextras/qmacnativetoolbar.mm:130:1: error: unknown type name 'QT_NAMESPACE_ALIAS_OBJC_CLASS'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSToolbarNotifier);
    /Users/user/Desktop/qt-qtmacextras/src/macextras/qmacnativetoolbar.mm:138:5: error: reference to 'QtNSToolbar' is ambiguous
    QtNSToolbar *toolbar;
    /Users/user/Desktop/qt-qtmacextras/src/macextras/qnstoolbar.h:60:31: note: candidate found by name lookup is 'QtNSToolbar'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QtNSToolbar);
    /Users/user/Desktop/qt-qtmacextras/src/macextras/qnstoolbar.h:56:32: note: candidate found by name lookup is 'QtNSToolbar'
    @interface QT_MANGLE_NAMESPACE(QtNSToolbar) : NSToolbar
    /Users/user/Qt/5.1.0/clang_64/include/QtCore/qglobal.h:98:36: note: expanded from macro 'QT_MANGLE_NAMESPACE'

    define QT_MANGLE_NAMESPACE(name) name

    /Users/user/Desktop/qt-qtmacextras/src/macextras/qmacnativetoolbar.mm:139:5: error: reference to 'QMacToolbarDelegate' is ambiguous
    QMacToolbarDelegate *delegate;
    /Users/user/Desktop/qt-qtmacextras/src/macextras/qmactoolbardelegate.h:84:31: note: candidate found by name lookup is 'QMacToolbarDelegate'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacToolbarDelegate);
    /Users/user/Desktop/qt-qtmacextras/src/macextras/qmactoolbardelegate.h:56:32: note: candidate found by name lookup is 'QMacToolbarDelegate'
    @interface QT_MANGLE_NAMESPACE(QMacToolbarDelegate) : NSObject <NSToolbarDelegate>
    /Users/user/Qt/5.1.0/clang_64/include/QtCore/qglobal.h:98:36: note: expanded from macro 'QT_MANGLE_NAMESPACE'

    define QT_MANGLE_NAMESPACE(name) name

    /Users/user/Desktop/qt-qtmacextras/src/macextras/qmacnativetoolbar.mm:140:5: error: reference to 'QNSToolbarNotifier' is ambiguous
    QNSToolbarNotifier *notifier;
    /Users/user/Desktop/qt-qtmacextras/src/macextras/qmacnativetoolbar.mm:130:31: note: candidate found by name lookup is 'QNSToolbarNotifier'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSToolbarNotifier);
    /Users/user/Desktop/qt-qtmacextras/src/macextras/qmacnativetoolbar.mm:122:32: note: candidate found by name lookup is 'QNSToolbarNotifier'
    @interface QT_MANGLE_NAMESPACE(QNSToolbarNotifier) : NSObject
    /Users/user/Qt/5.1.0/clang_64/include/QtCore/qglobal.h:98:36: note: expanded from macro 'QT_MANGLE_NAMESPACE'

    define QT_MANGLE_NAMESPACE(name) name

    /Users/user/Desktop/qt-qtmacextras/src/macextras/qmacnativetoolbar.mm:145:21: error: reference to 'QtNSToolbar' is ambiguous
    toolbar = [[QtNSToolbar alloc] initWithIdentifier:QtMacExtras::toNSString(identifier.isEmpty() ? QUuid::createUuid().toString() : identifier)];
    /Users/user/Desktop/qt-qtmacextras/src/macextras/qnstoolbar.h:60:31: note: candidate found by name lookup is 'QtNSToolbar'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QtNSToolbar);@ (I can't post the whole error messages but here is first part)

    I tested with Qt 5.1 and Mac OS X 10.8.4



  • Well, this is exactly the configuration I have, and on my computer MacExtras compiles without errors. I have just checked it again. I will think some more about what could go wrong, but since I never had any issues compiling it without any changes on different versions of Qt, I gather there must be something wrong with your configuration.



  • What I could to check in my configuration? Did you use latest source code?



  • Hi jimcad,

    I have just removed my copy of MacExtras and pulled it again from Gitorius, just in case. It compiles without errors on my computer. But the strange thing is that I am not for the moment able to find where the QT_NAMESPACE_ALIAS_OBJC_CLASS macro that gives you an error is defined. I ran a few searches across Qt installation, and it is not there. It must be defined on my system since it compiles fine, and it must be undefined on yours because it errors out, but I can't find where it is supposed to be located :).



  • Hi all,

    I have the same compilation problem as jimcad.

    It appears the last commit on gitorious introduce this weird marco:
    http://qt.gitorious.org/qt/qtmacextras/commit/3e21bfb18623a3ab9a9b31d489ae20f06e223c5d/diffs/8783de7f082c7a60821127ed8964884bae31a817

    The version just before compiles without issues.

    But I'm unable to link QtMacExtra with my project.
    http://stackoverflow.com/questions/17344884/link-issues-with-qtmacextras-using-qt-5-0-2

    Sincerely,



  • PysCowboy,
    Did you properly install your compiled MacExtras (i.e. make install in the build folder)?



  • Help, how can I do, what error?!

    In file included from qmacnativetoolbar.mm:45:
    ./qmactoolbardelegate_p.h:84:1: error: unknown type name 'QT_NAMESPACE_ALIAS_OBJC_CLASS'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacToolbarDelegate);
    ^
    In file included from qmacnativetoolbar.mm:46:
    ./qnstoolbar_p.h:60:1: error: unknown type name 'QT_NAMESPACE_ALIAS_OBJC_CLASS'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QtNSToolbar);
    ^
    qmacnativetoolbar.mm:130:1: error: unknown type name 'QT_NAMESPACE_ALIAS_OBJC_CLASS'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSToolbarNotifier);
    ^
    qmacnativetoolbar.mm:138:5: error: reference to 'QtNSToolbar' is ambiguous
    QtNSToolbar *toolbar;
    ^
    ./qnstoolbar_p.h:60:31: note: candidate found by name lookup is 'QtNSToolbar'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QtNSToolbar);
    ^
    ./qnstoolbar_p.h:56:32: note: candidate found by name lookup is 'QtNSToolbar'
    @interface QT_MANGLE_NAMESPACE(QtNSToolbar) : NSToolbar
    ^
    /usr/local/Qt-5.1.1/include/QtCore/qglobal.h:98:36: note: expanded from macro 'QT_MANGLE_NAMESPACE'

    define QT_MANGLE_NAMESPACE(name) name

                                   ^
    

    qmacnativetoolbar.mm:139:5: error: reference to 'QMacToolbarDelegate' is ambiguous
    QMacToolbarDelegate *delegate;
    ^
    ./qmactoolbardelegate_p.h:84:31: note: candidate found by name lookup is 'QMacToolbarDelegate'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacToolbarDelegate);
    ^
    ./qmactoolbardelegate_p.h:56:32: note: candidate found by name lookup is 'QMacToolbarDelegate'
    @interface QT_MANGLE_NAMESPACE(QMacToolbarDelegate) : NSObject <NSToolbarDelegate>
    ^
    /usr/local/Qt-5.1.1/include/QtCore/qglobal.h:98:36: note: expanded from macro 'QT_MANGLE_NAMESPACE'

    define QT_MANGLE_NAMESPACE(name) name

                                   ^
    

    qmacnativetoolbar.mm:140:5: error: reference to 'QNSToolbarNotifier' is ambiguous
    QNSToolbarNotifier *notifier;
    ^
    qmacnativetoolbar.mm:130:31: note: candidate found by name lookup is 'QNSToolbarNotifier'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSToolbarNotifier);
    ^
    qmacnativetoolbar.mm:122:32: note: candidate found by name lookup is 'QNSToolbarNotifier'
    @interface QT_MANGLE_NAMESPACE(QNSToolbarNotifier) : NSObject
    ^
    /usr/local/Qt-5.1.1/include/QtCore/qglobal.h:98:36: note: expanded from macro 'QT_MANGLE_NAMESPACE'

    define QT_MANGLE_NAMESPACE(name) name

                                   ^
    

    qmacnativetoolbar.mm:145:21: error: reference to 'QtNSToolbar' is ambiguous
    toolbar = [[QtNSToolbar alloc] initWithIdentifier:QtMac::toNSString(identifier.isEmpty() ? QUuid::createUuid().toString() : identifier)];
    ^
    ./qnstoolbar_p.h:60:31: note: candidate found by name lookup is 'QtNSToolbar'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QtNSToolbar);
    ^
    ./qnstoolbar_p.h:56:32: note: candidate found by name lookup is 'QtNSToolbar'
    @interface QT_MANGLE_NAMESPACE(QtNSToolbar) : NSToolbar
    ^
    /usr/local/Qt-5.1.1/include/QtCore/qglobal.h:98:36: note: expanded from macro 'QT_MANGLE_NAMESPACE'

    define QT_MANGLE_NAMESPACE(name) name

                                   ^
    

    qmacnativetoolbar.mm:148:22: error: reference to 'QMacToolbarDelegate' is ambiguous
    delegate = [[QMacToolbarDelegate alloc] init];
    ^
    ./qmactoolbardelegate_p.h:84:31: note: candidate found by name lookup is 'QMacToolbarDelegate'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacToolbarDelegate);
    ^
    ./qmactoolbardelegate_p.h:56:32: note: candidate found by name lookup is 'QMacToolbarDelegate'
    @interface QT_MANGLE_NAMESPACE(QMacToolbarDelegate) : NSObject <NSToolbarDelegate>
    ^
    /usr/local/Qt-5.1.1/include/QtCore/qglobal.h:98:36: note: expanded from macro 'QT_MANGLE_NAMESPACE'

    define QT_MANGLE_NAMESPACE(name) name

                                   ^
    

    qmacnativetoolbar.mm:151:22: error: reference to 'QNSToolbarNotifier' is ambiguous
    notifier = [[QNSToolbarNotifier alloc] init];
    ^
    qmacnativetoolbar.mm:130:31: note: candidate found by name lookup is 'QNSToolbarNotifier'
    QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSToolbarNotifier);
    ^
    qmacnativetoolbar.mm:122:32: note: candidate found by name lookup is 'QNSToolbarNotifier'
    @interface QT_MANGLE_NAMESPACE(QNSToolbarNotifier) : NSObject
    ^
    /usr/local/Qt-5.1.1/include/QtCore/qglobal.h:98:36: note: expanded from macro 'QT_MANGLE_NAMESPACE'

    define QT_MANGLE_NAMESPACE(name) name

                                   ^
    

    qmacnativetoolbar.mm:579:17: warning: cannot find interface declaration for 'QNSToolbarNotifier'
    @implementation QNSToolbarNotifier
    ^
    qmacnativetoolbar.mm:585:9: error: use of undeclared identifier 'pimpl'
    pimpl->fireVisibilityChanged();
    ^
    qmacnativetoolbar.mm:587:9: error: use of undeclared identifier 'pimpl'
    pimpl->fireShowsBaselineSeparatorChanged();
    ^
    qmacnativetoolbar.mm:589:9: error: use of undeclared identifier 'pimpl'
    pimpl->fireToolButtonStyleChanged();
    ^
    qmacnativetoolbar.mm:591:9: error: use of undeclared identifier 'pimpl'
    pimpl->fireSizeModeChangedNotification();
    ^
    qmacnativetoolbar.mm:593:9: error: use of undeclared identifier 'pimpl'
    pimpl->fireAllowsUserCustomizationChanged();
    ^
    qmacnativetoolbar.mm:579:17: warning: class 'QNSToolbarNotifier' defined without specifying a base class [-Wobjc-root-class]
    @implementation QNSToolbarNotifier
    ^
    qmacnativetoolbar.mm:579:35: note: add a super class to fix this problem
    @implementation QNSToolbarNotifier
    ^
    : NSObject



  • Hi,

    QtMacExtras is now part of Qt 5.2 Beta. I tried to figure how to use native toolbar on OS X but I haven't found a solution. Could someone help me?

    Thanks in advance.


Log in to reply
 

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