首先vs要安装QT 插件。QT VS Tools
然后右键工程目录里面需要建立UI文件的文件夹,添加-》新建项,选择QT,出现QT UI模板,选择需要的。
qt001.jpg
然后加入对应的xx.h 和xx.cpp
DlgRooms.h
#pragma once
#include <QDialog>
#include "ui_DlgRooms.h"
class DlgRooms : public QDialog
{
Q_OBJECT
public slots:
void myClick();
public:
QJsonObject UrlRequestPost(const QString url, const QString data);
DlgRooms(QWidget *parent = Q_NULLPTR);
~DlgRooms();
private:
Ui::DlgRooms ui;
};
DlgRooms.cpp
#include "DlgRooms.h"
#include <QCryptographicHash>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QEventLoop>
#include <QTextCodec>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMessageBox>
#include "obs-app.hpp"
DlgRooms::DlgRooms(QWidget *parent): QDialog(parent){
ui.setupUi(this);
//connect(ui.okButton, SIGNAL(clicked()), this, SLOT(ClickButton()));
}
DlgRooms::~DlgRooms(){
}
void DlgRooms::myClick() {
QString un = "";// ui.ltUserName->text();
QString pwd = "";// ui.lePassword->text();
QMessageBox box(QMessageBox::Warning, "", "用户名密码错误!");
box.exec();
}
QJsonObject DlgRooms::UrlRequestPost(const QString url, const QString data)
{
QJsonObject object;
return object;
}
之后还要添加到CMakeList.txt
set(obs_SOURCES
${obs_PLATFORM_SOURCES}
${obs_libffutil_SOURCES}
../deps/json11/json11.cpp
obs-app.cpp
api-interface.cpp
DlgRooms.cpp
.
.
.
set(obs_HEADERS
${obs_PLATFORM_HEADERS}
${obs_libffutil_HEADERS}
../deps/json11/json11.hpp
obs-app.hpp
platform.hpp
DlgRooms.h
.
.
.
OK 了。 UI文件在QT设计师中编辑。然后绑定信号,槽神马的就可以了。
网友评论