I'm using Necessitas to compile and run my QT apps on Android. If I'd like to show another window over the Main Wondow, I would create an UI file from QT Creator, which also will create a class. Then, I would create an instance of that class, and finally call the exec() member function.
However, in Necessitas QT Creator, the compiler tells me that the memeber function exec() doesen't exist. If I try using the show() member function, nothing happens. Also , If I hide the Main Window, the program exits.
So ,what can I do to show the other Window that I created with QT Creator?
http://qt-project.org/doc/qt-4.8/qstackedwidget.html
This is essentially a layout that behaves like a tabbed/paged widget but it doesn't show any tabs. This should get you what you want.
Related
I'm writing an app in Qt Creator, using C++. The eventual goal is to have control over an OpenGL window from within the Qt main winow.
Initialization is fine, both mainwindow and OpenGL window start up with no issues.
The mainwindow is subclassed from QMainwindow, the OpenGL window is subclassed from public QWindow, public QOpenGLFunctions.
Here's the crux of the problem. I want event handlers in mainwindow to have access to the OpenGLWindow. I can't seem to make that happen. I've gotten past a number of obstacles so at this point I have the following set-up;
In main.cpp, I declare the objects for both mainwindow and OpenGLWindow. I have the mainwindow mousepressed event handler in main.cpp. As is, all works fine. Both windows come up as they should, and the event handler code does exactly what I want it to do in the mainwindow, just print some text in a textbox.
In order to have access to the openglwindow from the event handler in main.cpp, I declare the OpenGLWindow object as global, outside of the main () main.cpp (is this bad technique?).
Everything compiles fine, but when I run it I get the error 'QPixmap: Must construct a QGuiApplication before a QPixmap'. I assume that this means that the system is not happy that I am creating the OpenGLWindow before the application object.
Is there a more elegant way to do this? Am I a few lines away from correct code, or does this need some major rearranging.
BTW - I am doing this in Windows 10. The main reason I have chosen Qt and OpenGL for this app is that I want it portable to Linux.
I'm working on a tool, on the main window of the tool there are few Qt widgets added on it.
When we used to RMB click on the Qt widget, a context menu pops up (and via eventFilter few functions have been called) to do the required work- say, doTask() slot gets called up with the receiver object.
Now I have to add a banner menu on the window, which has to copy all the features of RMB context menu.
Since this banner menu is not of Qt, but written in some internal functions (say, LISP) I have problems in calling that slot function - doTask(), as I don't know what is the receiver object.
How can I communicate with a Qt widget through some external command/language?
Please add comment if anything is not clear in this.
Can you not expose a simple C style method from a QT aware object that acts as a proxy for the slot calls. ie Your banner calls method, method then calls appropriate slots?
Your basic problem is just knowing the receiver object. Once you do, you can call its slot directly (doesn't need to go through a signal).
The menu knows this, because it keeps a pointer to the receiver object. Your own banner menu must do the same. "It doesn't know the receiver object" must therefore be fixed.
How can I acces other ui files from code using Qt Creator?
I am trying to create a small text editor. As always, I designed the main window by pressing on the Design button . After that , I created a new ui file from Qt creator called about.ui (the IDE also added about.h and about.cpp ). The main window's functions(like on_button_cliked() ) are in the file textedit.cpp
I created a small menu with an about entry, and then I went to Action Editor ,I selected the entry , Go to Slot, and the trigerred();
The IDE created all the things for me, so all I need is to define the function.
How can I acces the about ui that I created earlier?
Thanks in advance
You don't need the access to the '.ui' file. Qt's ui application does everything for you. All you need now is to create an object of your About class with MainWindow as a parent and show it.
The approximate code will be:
#include "about.h"
// ...
void MainWindow::on_about_triggered()
{
About dialog(this);
dialog.exec();
}
I have a little question about Qt custom Widgets.
Both in http://doc.qt.digia.com/4.3/tutorial-t4.html and http://doc.qt.digia.com/4.3/tutorial-t8.html, the custom window declaration is made in the main.cpp file, where the qApp pointer is accesible(in the second link, more widgets are declared in their own files).
Couldn't the window be done in another different file and have the qApp pointer passed to it?.
Yes, the main windows can be created in another file. All you need in the main is to create the QApplication and show something that you include. And then start the event loop.
You don't have to pass qApp pointer anywhere. It is a global reference to the only single application that can be running. Just access it in any other file by including QApplication.
Also be advised, those tutorials are for Qt 4.3 which is old (unless you are bound to use that version right now). You can find tutorials for Qt 4.8 here
I've been watching a Qt tutorial series on YouTube, in which the author shows how to call a function, when a button is pressed. He right-clicked on the button in Qt Creator IDE and chose "Go to slot", from where he chose the signal which would fire the generated function. Since I am used to develop with Netbeans, I simply tried to follow his example using the embedded Qt Designer. Unfortunately, there is no "Go to slot..." entry when I right-click on my button or any widget. I could, of course, create a new slot for my main window and then connect the button's signal to it, but doing it with a single function just seems way more convenient and clean to me. Is there a way to fix is, or if not, at least a way to do with via code entirely, without having to add a new slot to the main window for every single button that servers a different purpose? Thanks for your help.
While I don't know why the QtDesigner in Netbeans doesn't provide this feature, I know what the feature does: It just creates a slot with a special name in your widget class. Note that it does not add a connect statement. It uses the automatic connection feature, which works like this:
For each slot which name matches this pattern:
void on_X_Y(...)
it will be connected to the signal named Y of the object named X. So if you have a QPushButton named button, and you want to handle the signal pressed, simply create a slot with the following signature:
void on_button_pressed()
If you wonder how this slot gets connected to the signal: This happens in the ui_...h file at the end of setupUi():
QMetaObject::connectSlotsByName(WidgetName);