网站备案怎么转入,建设旅游网站需要多少钱,wordpress开发复杂网站,提升学历的目的和意义前言: 以前 windows下做工具主要是MFC#xff0c;趁有点空时间#xff0c;研究了QT#xff0c;感觉跟MFC 差不多#xff0c;VS 比 QT CREATOR 还是强大#xff0c;不过QT可以跨平台#xff0c;功能更强大#xff0c;MFC 只能在win平台下.#xff1b; 1#xff1a;环境…前言: 以前 windows下做工具主要是MFC趁有点空时间研究了QT感觉跟MFC 差不多VS 比 QT CREATOR 还是强大不过QT可以跨平台功能更强大MFC 只能在win平台下. 1环境 win10 Qt 6.8 LTS Qt Creator 14.0.2 MINGW :13.1 download:https://download.qt.io/official_releases/online_installers/ 选择 qt-unified-windows-x64-online.exe 2安装 已经安装好了真是吃硬盘 最少准备40G用QT一定要用ssd最差是sata3最好是m2 pcie3及以上,512G起吧,IOPS 差用起来难受 3常用控件 左边MFC(VS2022) 右边 为 qt的 常用控件都差不多,会MFC只要稍微熟悉了基本用法就OK了常用控件都这样;
4qt跟MFC 对比注意事项 1 创建工程 qt 选择cmake(qmake,cmake,qbs) cmake 相对比较熟悉linux下编译用到 MFC 选择MFC应用
下面简单的做个DMO 几个button tableview menu dialog 等 直接上代码 mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include QMainWindow
#include QButtonGroup
#include qitemselectionmodel.h
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACEclass MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent nullptr);~MainWindow();private:Ui::MainWindow *ui;QButtonGroup * m_group1;public slots:void ClickButton_previous(bool b);void ClickButton_previous2();void onBtnFunc(int n);void btnToggled(int,bool);void slotselectionChanged(const QItemSelection selected, const QItemSelection deselected);void receiveData(QString data);
};
#endif // MAINWINDOW_Hmainwindow.cpp
#include mainwindow.h
#include ./ui_mainwindow.h
#include dialog.h#include QStandardItemModel
#include QStringListModel
#include mylistmodel.h
#include qlogging.hMainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui-setupUi(this);//查找名为label_2的QLabel对象并返回QLabel * re2 findChildQLabel*(label1);re2-setText(test111);// QAction * p new QAction();// connect(newAction, QAction::triggered, this, MainWindow::onNewFile);//connect(action, SIGNAL(triggered()), this, SLOT(onFileNew()));// QAction
// public Q_SLOTS:
// void trigger() { activate(Trigger); }
// void hover() { activate(Hover); }
// void setChecked(bool);
// void toggle();
// void setEnabled(bool);
// void resetEnabled();
// inline void setDisabled(bool b) { setEnabled(!b); }
// void setVisible(bool);// Q_SIGNALS:
// void changed();
// void enabledChanged(bool enabled);
// void checkableChanged(bool checkable);
// void visibleChanged();
// void triggered(bool checked false);
// void hovered();
// void toggled(bool);//SIGNAL SLOT 带参数要统一不然找不到///ok1// QMetaObject::Connection c1 connect(ui-action111_111, SIGNAL(triggered(bool)), this, SLOT(ClickButton_previous(bool)));// if(c1 ! NULL){// qDebug(3333);// }// QAction *newAction new QAction(tr(New), this);//connect(newAction, QAction::triggered, this, MainWindow::onNewFile);///ok2QMetaObject::Connection c1 connect(ui-action111_111, QAction::triggered, this, MainWindow::ClickButton_previous);if (c1 ! NULL){}//button
// public Q_SLOTS:
// void setIconSize(const QSize size);
// void animateClick();
// void click();
// void toggle();
// void setChecked(bool);// Q_SIGNALS:
// void pressed();
// void released();
// void clicked(bool checked false);
// void toggled(bool checked);QMetaObject::Connection c2 connect(ui-pushButton1, SIGNAL(clicked()), this, SLOT(ClickButton_previous2()));if(c2 ! NULL){qDebug(3333);}connect(ui-pushButton2,QPushButton::clicked,[](){re2-setText(pushButton2);});//qradiobutton// 连接信号与槽函数m_group1 new QButtonGroup(this);m_group1-addButton (ui-radioButton, 0);m_group1-addButton (ui-radioButton_2, 1);m_group1-setExclusive(true);//connect (m_group1, SIGNAL (buttonClicked(int)), this, SLOT(onBtnFunc(int)));connect (m_group1, SIGNAL(idToggled(int,bool)), this, SLOT(btnToggled(int,bool)));// connect(ui-radioButton, SIGNAL(idToggled(int,bool)), this, SLOT(btnToggled(int,bool)));// connect(ui-groupBox1, QRadioButton::toggled, this, SLOT(btnToggled(int,bool)));QStandardItemModel *model new QStandardItemModel();// 添加列头model-setHorizontalHeaderLabels(QStringList() Column 1 Column 2 Column 3);// 添加数据for (int row 0; row 10; row) {for (int col 0; col 3; col) {QStandardItem *item new QStandardItem(QString(Row %1, Column %2).arg(row).arg(col));model-setItem(row, col, item);}}QTableView *tableView ui-tableView1;tableView-setModel(model);tableView-setSelectionBehavior(QAbstractItemView::SelectRows);// 显示窗口// tableView-show();//选择行事件//ok_1// QObject::connect(tableView-selectionModel(), QItemSelectionModel::selectionChanged,// [](const QItemSelection selected, const QItemSelection deselected){// QModelIndexList indexes selected.indexes();// if (!indexes.isEmpty()) {// QModelIndex firstIndex indexes.first();// qDebug() Row firstIndex.row() selected.;// }// });// public Q_SLOTS:// virtual void setCurrentIndex(const QModelIndex index, QItemSelectionModel::SelectionFlags command);// virtual void select(const QModelIndex index, QItemSelectionModel::SelectionFlags command);// virtual void select(const QItemSelection selection, QItemSelectionModel::SelectionFlags command);// virtual void clear();// virtual void reset();// void clearSelection();// virtual void clearCurrentIndex();// Q_SIGNALS:// void selectionChanged(const QItemSelection selected, const QItemSelection deselected);// void currentChanged(const QModelIndex current, const QModelIndex previous);// void currentRowChanged(const QModelIndex current, const QModelIndex previous);// void currentColumnChanged(const QModelIndex current, const QModelIndex previous);// void modelChanged(QAbstractItemModel *model);//ok_2///connect(tableView-selectionModel(),QItemSelectionModel::selectionChanged,this,MainWindow::slotselectionChanged);
}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::ClickButton_previous(bool b){QLabel * re2 findChildQLabel*(label1);re2-setText(test2221);//click menuqDebug()dialog top;Dialog dialog(this);//子窗口给父窗口发送消息//connect(sender, SenderClass::signalName, receiver, ReceiverClass::slotName);connect(dialog, Dialog::sendData,this,MainWindow::receiveData);//连接信号与槽dialog.show(); //or connect(child, child::sendData,this,MainWindow::receiveData);//连接信号与槽dialog.exec(); //以模态方式打开对话框打开主窗口时不能使用主窗口
}void MainWindow::ClickButton_previous2(){QLabel * re2 findChildQLabel*(label1);re2-setText(test3333);
}void MainWindow::onBtnFunc(int n)
{quint16 a m_group1-checkedId();QLabel * re2 findChildQLabel*(label1);QString q onBtnFuncQString::number(n);re2-setText(q);}void MainWindow::btnToggled(int n ,bool b){qDebug()nb;QLabel * re2 findChildQLabel*(label1);QString q QString::number(n)onBtnFunc;re2-setText(q);
}
//
void MainWindow::slotselectionChanged(const QItemSelection selected, const QItemSelection deselected){QModelIndexList indexes selected.indexes();if (!indexes.isEmpty()) {QModelIndex firstIndex indexes.first();qDebug() Row firstIndex.row() selected.;}
}void MainWindow::receiveData(QString data)//接收子窗口发送的数据
{qDebug()recv dialog msgdata ;
}dialog.h
#ifndef DIALOG_H
#define DIALOG_H#include QDialognamespace Ui {
class Dialog;
}class Dialog : public QDialog
{Q_OBJECTpublic:explicit Dialog(QWidget *parent nullptr);~Dialog();private slots:void on_pushButton_clicked();
public :signals:void sendData(QString data); //点击发送时发送的QString型data信号 给 主窗口 private:Ui::Dialog *ui;
};#endif // DIALOG_Hdialog.cpp
#include dialog.h
#include ui_dialog.h
#include QObject
// #define SIGNAL(arg) #arg
// #define SLOT(arg) #argDialog::Dialog(QWidget *parent): QDialog(parent), ui(new Ui::Dialog)
{ui-setupUi(this);connect(ui-pushButton, QPushButton::clicked, this, Dialog::on_pushButton_clicked);
}Dialog::~Dialog()
{delete ui;
}void Dialog::on_pushButton_clicked()
{qDebug()Dialog;emit sendData(Dialog); //
}connect(button, SIGNAL(clicked()), this, SLOT(handleButtonClicked())); connect(sender, SenderClass::signalName, receiver, ReceiverClass::slotName); 有重载函数时可以用 qOverload 指明 void do_click(bool b) connect(sender, SenderClass::signalName, this, qOverload(Widget::do_click)); //函数里带参数bool b void do_click() connect(sender, SenderClass::signalName, this, qOverload(Widget::do_click));//函数里不带参数 一个信号可以连接多个slot 类试于 Observer Pattern观察者模式 connect(sender, SenderClass::signalName, receiver1, ReceiverClass1::slotName); connect(sender, SenderClass::signalName, receiver2, ReceiverClass2::slotName);
5测试结果 6:如果觉得有用麻烦点个赞加个收藏 下章讲述 qml感觉跟lua 类试都可以相互调用 文章转载自: http://www.morning.ltpzr.cn.gov.cn.ltpzr.cn http://www.morning.dgxrz.cn.gov.cn.dgxrz.cn http://www.morning.rtkz.cn.gov.cn.rtkz.cn http://www.morning.qbmjf.cn.gov.cn.qbmjf.cn http://www.morning.ymqfx.cn.gov.cn.ymqfx.cn http://www.morning.cgntj.cn.gov.cn.cgntj.cn http://www.morning.xkjrs.cn.gov.cn.xkjrs.cn http://www.morning.yskhj.cn.gov.cn.yskhj.cn http://www.morning.jhqcr.cn.gov.cn.jhqcr.cn http://www.morning.pphbn.cn.gov.cn.pphbn.cn http://www.morning.skmzm.cn.gov.cn.skmzm.cn http://www.morning.zlkps.cn.gov.cn.zlkps.cn http://www.morning.dtlqc.cn.gov.cn.dtlqc.cn http://www.morning.yrmpz.cn.gov.cn.yrmpz.cn http://www.morning.elsemon.com.gov.cn.elsemon.com http://www.morning.txhls.cn.gov.cn.txhls.cn http://www.morning.0small.cn.gov.cn.0small.cn http://www.morning.jlboyuan.cn.gov.cn.jlboyuan.cn http://www.morning.ypqwm.cn.gov.cn.ypqwm.cn http://www.morning.lkkkf.cn.gov.cn.lkkkf.cn http://www.morning.mhlsx.cn.gov.cn.mhlsx.cn http://www.morning.hyhqd.cn.gov.cn.hyhqd.cn http://www.morning.fwkq.cn.gov.cn.fwkq.cn http://www.morning.csjps.cn.gov.cn.csjps.cn http://www.morning.hzqjgas.com.gov.cn.hzqjgas.com http://www.morning.lksgz.cn.gov.cn.lksgz.cn http://www.morning.qjmnl.cn.gov.cn.qjmnl.cn http://www.morning.nnykz.cn.gov.cn.nnykz.cn http://www.morning.qpfmh.cn.gov.cn.qpfmh.cn http://www.morning.snrhg.cn.gov.cn.snrhg.cn http://www.morning.fbmzm.cn.gov.cn.fbmzm.cn http://www.morning.bby45.cn.gov.cn.bby45.cn http://www.morning.bwfsn.cn.gov.cn.bwfsn.cn http://www.morning.nyfyq.cn.gov.cn.nyfyq.cn http://www.morning.tjwfk.cn.gov.cn.tjwfk.cn http://www.morning.zlwg.cn.gov.cn.zlwg.cn http://www.morning.xrqkm.cn.gov.cn.xrqkm.cn http://www.morning.zkrzb.cn.gov.cn.zkrzb.cn http://www.morning.wbysj.cn.gov.cn.wbysj.cn http://www.morning.ddzqx.cn.gov.cn.ddzqx.cn http://www.morning.tqhpt.cn.gov.cn.tqhpt.cn http://www.morning.gwsll.cn.gov.cn.gwsll.cn http://www.morning.dnqlba.cn.gov.cn.dnqlba.cn http://www.morning.hclplus.com.gov.cn.hclplus.com http://www.morning.wqtzs.cn.gov.cn.wqtzs.cn http://www.morning.kzcfr.cn.gov.cn.kzcfr.cn http://www.morning.ksgjn.cn.gov.cn.ksgjn.cn http://www.morning.nspbj.cn.gov.cn.nspbj.cn http://www.morning.lizimc.com.gov.cn.lizimc.com http://www.morning.zlgth.cn.gov.cn.zlgth.cn http://www.morning.kdrly.cn.gov.cn.kdrly.cn http://www.morning.lfpzs.cn.gov.cn.lfpzs.cn http://www.morning.rfwqt.cn.gov.cn.rfwqt.cn http://www.morning.wbns.cn.gov.cn.wbns.cn http://www.morning.cjrmf.cn.gov.cn.cjrmf.cn http://www.morning.wkkqw.cn.gov.cn.wkkqw.cn http://www.morning.gyqnc.cn.gov.cn.gyqnc.cn http://www.morning.shsh1688.com.gov.cn.shsh1688.com http://www.morning.bqyb.cn.gov.cn.bqyb.cn http://www.morning.pmftz.cn.gov.cn.pmftz.cn http://www.morning.zfzgp.cn.gov.cn.zfzgp.cn http://www.morning.tnwwl.cn.gov.cn.tnwwl.cn http://www.morning.kxnnh.cn.gov.cn.kxnnh.cn http://www.morning.vibwp.cn.gov.cn.vibwp.cn http://www.morning.fhxrb.cn.gov.cn.fhxrb.cn http://www.morning.mjpgl.cn.gov.cn.mjpgl.cn http://www.morning.fqqcd.cn.gov.cn.fqqcd.cn http://www.morning.dmcqy.cn.gov.cn.dmcqy.cn http://www.morning.fkcjs.cn.gov.cn.fkcjs.cn http://www.morning.plqqn.cn.gov.cn.plqqn.cn http://www.morning.dmwjl.cn.gov.cn.dmwjl.cn http://www.morning.mdmc.cn.gov.cn.mdmc.cn http://www.morning.hybmz.cn.gov.cn.hybmz.cn http://www.morning.kkwbw.cn.gov.cn.kkwbw.cn http://www.morning.sjzsjsm.com.gov.cn.sjzsjsm.com http://www.morning.pndhh.cn.gov.cn.pndhh.cn http://www.morning.mytmn.cn.gov.cn.mytmn.cn http://www.morning.tgnwt.cn.gov.cn.tgnwt.cn http://www.morning.ttcmdsg.cn.gov.cn.ttcmdsg.cn http://www.morning.wschl.cn.gov.cn.wschl.cn