could anyone tell me the steps on how to add a .ui file to an existing class in Visual? Firstly I added a new item in Visual, then I chose "QT Dialog Form File" option and I then I created Dialog Form I desire in QT Designer.
My .h file:
(...)
#include "ui_Serial.h"
class Serial : public QWidget
{
Q_OBJECT
public:
Serial(QWidget *parent);
~Serial();
Ui::Serial *ui;
(...)
My problem is, that I can't use setup ui function:
Serial::Serial(QWidget *parent)
: QWidget(parent)
{
serial = new QSerialPort(this);
ui->setupUi(this);
}
I am getting this error: cannot convert argument 1 from 'Serial *' to 'QDialog *
How I can get pass that? Any ideas? Greetings
Each Template has a default class because when the .ui is built, class commands are embedded.
QWidget
. QDialog
. QMainWindow
. So we conclude in your case that you should use a class that inherits from QDialog:
*.h
#include "ui_Serial.h"
class Serial : public QDialog
{
Q_OBJECT
public:
Serial(QWidget *parent=0);
~Serial();
Ui::Serial *ui;
}
*.cpp
Serial::Serial(QWidget *parent):QDialog(parent)
{
serial = new QSerialPort(this);
ui->setupUi(this);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.