User Tools

Site Tools

blog:2021-02-23_qt_qmenu_operation



2021-02-23 Qt: QMenu Operation

  • I had create a menu in Qt application
  • This memo the menu connect to the operation and quit Qt application.

Method

  • I have two menu:
    • File: Quit
    • Log: Clear
  • mainwindow.cpp
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        Task_ProjectInitial(); // 專案初始化
        Menu_CreateActions(); // 建立Menu Action的串接
    }
  • I had created a MenuActions.cpp
    #include "project.h"
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    // Menu中的命令串接
    void MainWindow::Menu_CreateActions()
    {
        // File -> Quit, 直接退出程序
        connect(ui->actionQuit, SIGNAL(triggered()),qApp,SLOT(quit()));
        // Log -> Clear
        connect(ui->actionClear, SIGNAL(triggered()), this, SLOT(Menu_LogClear()));
    }
    
    void MainWindow::Menu_LogClear()
    {
        // 清除Log
        ui->textEdit_Log->clear();
    }
    
  • Now, it should be worked.

TAGS

  • 247 person(s) visited this page until now.

Permalink blog/2021-02-23_qt_qmenu_operation.txt · Last modified: 2021/02/23 14:53 by jethro

oeffentlich