Qt GUI in Visual Studio..New Added Widgets through Qt Designer inaccessible - c++

I wrote an application in Visual Studio and I needed to create a GUI for it so I decided to use Qt and I'm having a small but weird problem.
Let's say I add a Push button to the GUI in the Qt Designer. When I build the Application the UI Compiler creates the corresponding header file "ui_myApp.h" which has the new Push button.
When I Try to access the new Button and connect Signals and Slots the I can't find the Button. I only see old Widgets that I added before the Last build. It actually should show me "pushButton_2" and "pushButton_3" but I have only access to the pushButton and other Widgets before the last build.(See Figure)
I Checked the headerfile "ui_myApp.h" and the new Widgets are actually there. The Header file is correctly included. When I run my Application the new Button and new Widgets are there too. Why can't I access them when Connecting Signals and Slots in "myApp.cpp"??
Thanks!

Update
This may or may not help anyone. But if anyone ever faces the problem here how I solved it:
Each time I add new Widgets to my GUI using QT Designer I save the changes in the Form. Then I clean the Solution and Rebuild. Then I close Visual Studio and start it again. The new Widgets are accessible after these action. Not sure why.. but it does the job.

Related

How to add QDockWidgets as tab?

I'm trying to create a Qt application with tabified QDockWidgets.
I know there is a QMainWindow::tabifyDockWidget to tabify QDockWidgets but since I'm doing everything related to UI in Qt Designer, I was wondering if there is some option in the designer to do so without adding extra code.

How to disable automatic mnemonics in a Qt application on KDE?

In any Qt application on KDE when I add a QPushButton in designer and check it's text by:
void MainWindow::on_pushButton_clicked()
{
qDebug()<<ui->pushButton->text();
}
The output is preceded by an & :
&PushButton
This behavior does not exist on Windows. It seems that Qt applications on KDE automatically add shortcuts to all push buttons, which is not desired for me. I should note that the ampersands are not created by designer and you can not see them in the.ui file. Actually when the button is added to a widget, an & is placed somewhere in it's text.
Is it possible to disable automatic mnemonics of a Qt application in anyway?
KDEPlatformTheme plugin responsible for it.
A workaround is to add
[Development]
AutoCheckAccelerators=false
to ~/.config/kdeglobals, which prevents KDE from automatically adding accelerators.
Related bug: https://bugs.kde.org/show_bug.cgi?id=337491

Qt5 - Porting a Video Player from 4.8 to 5.1

I'm working on migrating my code from Qt 4.8.4 to Qt 5.1.1 and seemed to have run into a peculiar problem. Previously I was using the Phonon library's video widget to allow users to interact with the video. Since Phonon is no longer supported I was looking for a way to replace my Phonon widget via the Qt Designer but I found no replacement widget available. Does anyone know how we're supposed to go about porting this functionality?
If anyone has any insight, it is appreciated as always!
All the other answers provide very useful information, but since I was looking for a specific and functional implementation, I'm guessing people that stumble on this may be looking for one as well, so I'll post my code along with my thought process and a bit of background info of my setup.
videoWidget = new QVideoWidget;
player = new QMediaPlayer;
verticalLayout->addWidget(videoWidget);
player->setVideoOutput(videoWidget);
player->setMedia(QUrl::fromLocalFile("Resources\\videos\\example.m4v"));
videoWidget->show();
player->play();
So to go through this, basically in my project I have a widget that is a part of a stackwidget structure on which I have some QWidgets like playback control buttons, labels, etc, and I previously had my Phonon video player. I really really didn't want to generate it all programatically so I managed to find a solution.
The above code was located in this container widgets constructor. In the designer I have made a simple, empty verticalLayout, positioned and sized it to my liking. This allowed me to embed the QVideoWidget despite not having a interactive QWidget in the Designer. videoWidget, and player are declared as private in the container widget's header file.
You've already noted there's no more Phonon
Now what you've got is QtMultimedia and the QtMultimediaWidgets. If you want them available to your project and you're using Qmake, then change your QT line in your .pro file from something like:
QT += widgets
to:
QT += widgets multimediawidgets
That won't do anything about the designer interaction, though. I think it's probably a matter of no one having done the work to make a custom widget extension for QVideoWidget.
If that's correct, then if you want to place a QVideoWidget into your form via Qt designer you will have to use "Widget Promotion". Just put an ordinary QWidget into your layout, and then right click on it in the form and pick Promote to ...
As for the specifics of porting Phonon abilities to the new widgets, I dunno what's covered and what isn't. No answers here yet, either:
How to port Qt4.6 Phonon based media-application to Qt 5.1?
It seems that although Qt itself no longer includes Phonon, there is a Qt5 port available as an external library:
http://community.kde.org/Phonon/Releases/Core/4.7.0
Alternatively, you can switch to the new QtMultimedia APIs:
https://qt-project.org/doc/qt-5.1/qtmultimedia/videooverview.html

How do you programatically update the UI in Qt?

I'm fairly new to Qt, and am trying to wrap my head around signals and slots. Though I've figured out how to create custom slots, I've yet to figure out how do update the GUI from my C++ code. I realized that the entire UI, which I created in the designer, is only written in what appears to be XML based UI code. Do I have to handwrite my own Qt C++ UI in order to update the interface, or can I somehow use C++ to update the XML based UI? I'm just looking to add a widget to the main form on a button click. Any help is appreciated. Thanks!
To add a widget to a form you can simply do
ui->layout()->addWidget(new Widget);
XML is used by QtDesigner as a mean to create, update, and persist your GUI, enabling a visual approach to development, but in the end you can build your application entirely without it.
you dont havfe to update the xml of UI . you can inherit the ui into your own class using setupUi
http://crpppc19.epfl.ch/doc/qt4-doc-html/html/qwidget.html#setupUi
now in your C++ class you can update the widgets like changing label text, lineEdit text, setting up spinbox value using Signals & slot.
That xml is used by Qt designer and outside of designer it's only used by uic as a source to generate C++ code, so everything that you do in the designer end-up as C++ code, so it can be updated (or done completely) in C++ code (you can look into the code and see that you most likely have a member called ui that is most likely a pointer, but it can also be an instance of a C++ class that is generated for you by uic, and trough that ui member you can access the widgets and layouts that you created in the designer).
A generic resource that i recommend you to read can be found here and then (if you still can't figure it out) ask a specific question about what exactly are you trying to achieve.
LE: that link contains 3 methods to use the generated code into C++ code, don't try all of them into your working project, you may choose one method or use the default one (ui member pointer)

QT Creator - QStackedWidget pages proglem

I started new project in Qt Creator (Qt Widget Project > Qt Gui Application) and I can't make stacked widget work properly.
I don't know how to change pages in stacked widget which I added using ui. Program object structure looks like this:
MainWindow(QMainWindow)
> centralWidget(QCentralWidget)
> mainStackedWidget(QStackedWidget)
and mainStackedWidget has page1, page2, page3.
I tried few things but I failed.
Basically all my tries were to somehow use mainStackedWidget in main.cpp but I didn't manage to figure out how to use object, created in ui, in main.cpp.
Any ideas?
The function you want is QStackedWidget::setCurrentIndex() or QStackedWidget::setCurrentWidget().
If you did not use Qt Designer, just use:
mainStackedWidget->setCurrentIndex(index);
If you did use Qt Designer, you would probably use:
ui->mainStackedWidget->setCurrentIndex(index);