I'm trying to build a UI form and interface to it using the example from:
https://doc.qt.io/qt-5/designer-using-a-ui-file.html
#include "ui_item.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget widget;
Ui::Item ui;
ui.setupUi(&widget);
widget.show();
return app.exec();
}
However, it just doesn't work. In the line
ui.setupUi(&widget); I get the error:
invalid conversion from ‘QWidget*’ to ‘QFrame*’
Is there something I'm missing? The top-level widget in Ui::Item is a QFrame. I'm using Qt 5.12 and Qt-Creator 4.12.4.
The issue was that my UI top level was a QFrame and it needed to be a QWidget. For whatever reason, the UI file generated as a QFrame.
Related
I am using vtk QT, i've installed VTK, PCL libraries well, after run the project the realese mode; i found the following error.
QWidget: Must construct a QApplication before a QWidget
As the error message says, you will need to create a QApplication before you can instantiate and use a QWidget. For example:
#include <QApplication>
#include <QDialog>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDialog dialog;
dialog.setModal(true);
dialog.show();
return app.exec();
}
The app opens another widget as a pane. I guess this follows macOS guidelines but is it possible to force widget to open in another window?
Like this:
#include <QApplication>
#include <QMainWindow>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QMainWindow w;
w.setWindowTitle("Main Widget");
w.show();
QWidget anotherWidget;
anotherWidget.setWindowTitle("Another Widget");
anotherWidget.show();
return a.exec();
}
To do that, you need to set the flag of the second widget to Qt::Dialog
QWidget anotherWidget;
anotherWidget.setWindowTitle("Another Widget");
anotherWidget.setWindowFlag(Qt::Dialog);
anotherWidget.show();
Open the anotherWidget as a QMainWindow type instead of QWidget.
I have created a label in the form UI and I would like to make it display a GIF using code in main. This is what I have so far but I'm not sure what to put in place of the "???????". How can I make this label display a GIF?
#include "dialog.h"
#include <QApplication>
#include <QMovie>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
QMovie *movie = new QMovie(":/Gifs/Welcome_animation2.gif");
QLabel *lblMovie = new QLabel();
lblMovie->setMovie(??????????);
movie->start();
w.show();
return a.exec();
}
As pointed by CoryKramer, you should just use lblMovie->setMovie(movie). However, the problem seens to be that you're not setting the movie to the correct QLabel (ie. lblMovie is not the same object shown on your window)
You probably have to create the QMovie inside your Dialog class, and there you set the movie to the QLabel by using ui->lblMovie->setMovie(movie). If it really must be created outside, then you should add a public method to allow it.
Take a look at http://doc.qt.io/qt-5/gettingstartedqt.html for more information about proper usage of ui files
I have the following piece of code:
#include <QtWidgets/QtWidgets>
#include <QtMultimedia/QCamera>
#include <QtMultimedia/QMediaPlayer>
int main(int argc, char * argv[])
{
QApplication testQt(argc, argv);
QMainWindow w;
QWidget videoContainer(&w);
w.setCentralWidget(&videoContainer);
QVideoWidget videoWidget(&videoContainer);
QCamera cam(&w);
cam.setViewfinder(&videoWidget);
cam.start();
w.show();
return testQt.exec();
}
in which I am trying to create a main window, create a container widget to display video, create a videowidget in that container, and then finally set the viewfinder of the camera to that videowidget. However, when I try to do this I get the error
Variable has incomplete type 'QVideoWidget'
Why am I getting this error?
You need to include the corresponding header as follows:
#include <QVideoWidget>
You may also need to add this to your project file:
QT += multimediawidgets
I would like to ask if you could help me with my app.
I have an application in C++ using Qt (and Qwt) in MCVS 2010. I want to open QDialog window with QwtPlot on button click from Main Window (QMainWindow). Here is some code:
MainWindow.cpp
void MainWindow::on_pushButton_1_clicked ()
{
Dialog_plot dp;
dp.setModal(true);
dp.exec();
}
Dialog_plot.cpp:
#include <qwt_plot.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_curve.h>
#include "Dialog_plot.h"
Dialog_plot::Dialog_plot(QWidget *parent)
{
plot = new QwtPlot();
//more code...
main.cpp:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
This code is compiling, but when I click on that pushbutton_1 in my application I'm getting error:
Must construct a QApplication before a QPaintDevice
I know that such error was discussed many times and I was reading a lot about it but I can't see solution for my problem.
One more thing I would like to mention - I have similar application with Qwt plot written by somebody else and his application compiles and works without any problems in my MCVS. I was trying to compare Linker/libraries included but it seems to be the same. So I guess there is a problem with my application, I just can't solve it. I really need some help!