Qt: QTabWidget not responding to clicks - c++

I am creating a Qt GUI with C++.
My intention is to prompt the user when the tab bar is double clicked or single clicked. This works when I create the GUI using Qt Creator; however, when I qmake and run with XCode, the GUI does not respond to either single or double clicks.
I am using the signals tabBarDoubleClicked(int) and tabBarClicked(int) from QTabWidget.
Why do I experience different behavior when building with Qt Creator as opposed to XCode?
How can I make XCode recognize single and double clicks to the tabBar?
Edit: Also, I cannot find documentation for these functions. I find that strange due to Qt Creator listing this as applicable signals. Why?

One possible option is - as you write in the comment -, that you are using different Qt versions.
Another option in general is that people invoke qmake slightly different, e.g. from a different folder than QtCreator, etc.

Related

How to create an Evernote kind of widget for global menu of a MacOS/X desktop using QT?

How to create an application which stays in top of MacOS, something similar to below image. You can see the Evernote elephant icon.
I don't want to use xcode - because my application already built in QT, it has nice GUI, now I wanted to add extended feature something similar to Evernote. If I click on an elephant it will open a dialog box to write notes. In my case- it's a simple event like on/off buttons.
I have tried and created GUI widget apps but how to make one which resides like Evernote app ?
A custom pop up menu like the one pictured can be done several ways in Qt.
QML is the most modern way of making the menu with the customized styling you are looking for.
Apply the appropriate flags to the window/widget so it appears as a popup.
The same effects can also be done in QWidgets, but takes more code and probably will take longer to make. The flags you are looking for will be found under Qt Window Flags and/or under Qt Widget Attributes.
The stock stylings for Qt for different OS's deal mostly with title bars, status bars, buttons, drop downs, etc.
The base styles for Mac can be found here:
http://doc.qt.io/qt-5/gallery-macintosh.html
Once you go to a customized popup, you have to draw all of it yourself... but the native drawing elements in Qt are friendly enough and get you that look you are trying to do.
There are even some tools for exporting from Photoshop or Gimp directly to QML.
http://doc.qt.io/qtcreator/quick-export-to-qml.html
Hope that helps.
You are looking for a tray icon. Qt implements it in QSystemTrayIcon.
Further information
You may take a look at the System Tray Icon Example.
Many StackOverflow posts exist on this topic.
If you already have a program written for Qt, then you can compile and run it under MacOS/X much the same way you could compile it under (whatever OS you're using now). You'll need to install Xcode because Xcode includes the C++ compiler (clang) you'll need in order to compile your Qt program, but you don't have to use the Xcode IDE if you don't want to. Rather, you can either use the QtCreator IDE under MacOS/X, or you can simply open up a Terminal window and do a "qmake ; make" in the directory where your Qt-based program's .pro file is, and build it from the command line that way.
If, on the other hand, your question is actually about how to add an icon to the global menu of a MacOS/X desktop, then I don't think Qt has an API for that, so you'll need to drop down to using one of MacOS/X's native APIs. That will probably involve learning some Objective-C (or Objective-C++, if you prefer), but integrating a bit of Objective-C/C++ into your Qt app is doable with a bit of work.

Adding Qt to existing GNU C++ program

I have a current C++ program built using GNU make. It is reasonably large - about a dozen .cpp files and a similar number of headers.
It all runs off the command line and currently just outputs to cout and cerr.
I want to add Qt interface elements to it - what is the best way to do this?
(I have built some Qt stuff in the past (not for a few years) though I am rusty - the C++ code I have now works and I don't want to change that, just fix the way it outputs information to the end user.)
You didn't specify whether you're interested in Qt Widgets or Qt Quick, so I'll assume widgets.
Fire up Qt Creator, and create a new Qt Widgets project. Open designer mode by double clicking on the .ui file that was created and start creating the interface that you want. If you just want somewhere to start integrating your logic, dump your existing code into mainwindow.cpp (or whatever you called it) and refactor it as you learn more about Qt.
For example, one of your buttons might cause a slot to be invoked, and you could then do all of your stuff in that slot.
There are also a lot of non-gui-related utility classes like QCommandLineParser that may help you out.

Terminal to open a popup window in C++

My c++ application needs to display a message via a popup window or an alternative. My application is running on Ubuntu 12.04 version. Can I program the application to open a Ubuntu type popup window? If possible, how?
Do I need to use gnome window or something like that?
The simplest way to display a popup from a program that doesn't otherwise use a GUI, is probably just execute a command-line tool that does the work:
to display a notification with no buttons, you can use notify-send
system("/usr/bin/notify-send MessageSubject \"message body here\"");
if you want buttons so the user can give a response, you could use the (much uglier) xmessage
system("/usr/bin/xmessage")
(see each tool's manpage for all their options)
The alternative is really to use a full GUI framework (probably gtk+), and that's not typically a small change.
For example, you can use libnotify directly (giving you the same basic capabilities as notify-send, but more control), but this also depends on glib. So, now you've added two external dependencies when you could just have run system.
In order to display the popup or any kind of window, you will have to reference either gtk+ or qt libraries in your application/program. gtk+ is advisable, since the ubuntu unity desktop is also based on gtk+ - this way your program will have lesser overhead and more performance gain while running on ubuntu. You can either use the default C library (libgtk2.0) or the gtkmm (libgtkmm) for C++.
You can get more information on how to refer these libraries, initialize gtk_main in your main() function, etc. at this place: http://www.gtk.org/documentation.php

QMenuBar and QMenu doesn't show in Mac OS X

I'm using Qt 4.7.4 on Mac OS X 10.7.4, and I'm trying to add a QMenuBar and a QMenu to my application without success.
When looking for examples, I found the Basic Layouts and the screenshot of the interface on Windows displays the File menu, which is what I'm trying to do:
However, running this example on Mac OS X doesn't show the File menu inside the application window:
and it also doesn't show in the top Mac OS X bar:
It seems that this is either a bug of Qt 4.7.4 on Mac OS X, or we are required to do some tweaks on the source code to make it work on Mac.
How can I fix this problem?
I've found similar posts on Stack Overflow but none helped.
There is no problem in the code, nor in Qt. The example you cite only creates an Exit action in the menu. On OS X, such actions belong in the application menu, not in the File menu. Your application is called qt_menu, and that's how the application menu is called, and that's where you will find the Quit action -- Qt has correctly renamed it to agree with Apple's HIG. On Windows, it'd be customary to call it Exit, on a Mac it's bad style. Qt's behavior is correct, and I can reproduce it.
Add other actions to the file menu, or simply rename the one action from Exit to something else.
Note that Qt doesn't move actions directly based on their name. Qt guesses the action roles based on their name. You should override such guesses and set action roles explicitly using QAction::setMenuRole(). Those roles then get interpreted appropriately on various platforms.

Implementing drag and drop with QT 4.5 using QT Creator environment

We're about to commit to Qt and C++ (sigh) to do some cross-platform development. The latest version of Qt 4.5 seems very nice as does the QT Creator IDE, which although simple compared to other IDEs, is a good way to get started.
I'm trying to understand how to do drag and drop into QT widgets from the "outside" world. As far as I can tell from the documentation, you're supposed to subclass a widget that you want to have respond to drop events and override some methods (the dragEnterEvent and dropEvent member functions) for that widget.
But if I use the Qt Creator tool, I don't seem to have any access to the classes of the widgets that I have created using the GUI form builder and so I can't subclass them.
WHat's the secret?
Thanks in advance,
D
Someone on my team figured it out ---- turns out there is an option to "Promote" a widget, meaning you can subclass it to something else and then override the needed methods with no pain.
Seems to me it would have been more obvious if it said "Subclass widget..." rather than "Promote" but that's OK.
This QT Creator is a very nice piece of work.
I've never used QT creator environment, but I assume it spits out code afterward. Can you edit the code it spits out?
If you subclass the classes in a separate file, it shouldn't get overwritten when you rebuild your app with QT creator environment.
I suppose this is really a question for the QT creator forum though, sounds like a problem in THEIR user interface.