<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # :-: 添加狀態欄 在`mainwindows.h`里修改 ```css #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QTextEdit> //文本 #include <QMenu> //加入菜單 #include <QMenuBar> //加入菜單欄 #include <QAction> //加入菜單欄 #include <QFileDialog> QT_BEGIN_NAMESPACE class QTextEdit; QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); private: bool is_changed; QTextEdit *editor; //中央XextEdit控件 QString fileName; //當前文件的名字 //文件菜單 QMenu *file_menu; //文件菜單 QAction *new_file; //新建文件菜單項 QAction *open_file; //打開文件菜單項 QAction *save_file; //保存文件菜單項 QAction *exit_file; //退出文件菜單項 //編輯菜單 QMenu *edit_menu; //編輯菜單 QAction *copy_edit; //編輯菜單的復制按鈕 QAction *paste_edit; QAction *cut_edit; QAction *allselect_edit; QMenu *help_menu; //幫助菜單 //編譯菜單 QMenu *comp_menu; //編譯菜單 QAction *comp_comp; //編譯按鈕 QAction *run_comp; //運行按鈕 void precomp(); private slots: void on_exit();//在QT編輯環境,安裝ALT+ENTER,出現提示再按一次回車 void on_open(const QString &path = QString()); void on_save(); void on_new(); void on_copy(); void on_paste(); void on_cut(); void on_allselect(); void on_changed(); void on_comp(); void on_run(); void setupEditor(); void setupFileMenu(); void setupHelpMenu(); void about(); }; #endif // MAINWINDOW_H ``` 在`mainwindows.cpp`里修改 ```css #include <QtWidgets> #include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setupFileMenu(); setupHelpMenu(); setupEditor(); setCentralWidget(editor); setWindowTitle(tr("IDE")); //文本內容在保存前是否發生變動 is_changed = false; //添加菜單項,并為其設定快捷鍵 //【文件菜單欄】 file_menu = this->menuBar()->addMenu("文件"); new_file = new QAction("新建文件",this); //第一個參數是菜單項的文字,第二個參數是指向主體的指針 new_file ->setShortcut(tr("ctrl+n")); //設定快捷鍵 file_menu ->addAction(new_file); //關聯 菜單欄 與 菜單項 file_menu ->addSeparator(); //在文件下拉菜單上面顯示一個分隔符 open_file = new QAction("打開文件",this); file_menu ->addAction(open_file); open_file ->setShortcut(tr("ctrl+o")); save_file = new QAction("保存文件",this); file_menu ->addAction(save_file); save_file ->setShortcut(tr("ctrl+s")); exit_file = new QAction("退出",this); file_menu ->addAction(exit_file); //【編譯菜單欄】 comp_menu = this->menuBar()->addMenu("編譯"); comp_comp = new QAction("編譯",this); comp_menu->addAction(comp_comp); run_comp = new QAction("運行",this); comp_menu->addAction(run_comp); //【幫助菜單欄】 help_menu = this->menuBar()->addMenu("幫助"); //【鼠標事件與函數關聯】當鼠標點擊exit_file 菜單的時候,執行on_exit()函數 connect(exit_file,SIGNAL(triggered()),this,SLOT(on_exit())); connect(open_file,SIGNAL(triggered()),this,SLOT(on_open())); connect(save_file,SIGNAL(triggered()),this,SLOT(on_save())); connect(new_file,SIGNAL(triggered()),this,SLOT(on_new())); connect(copy_edit,SIGNAL(triggered()),this,SLOT(on_copy())); connect(paste_edit,SIGNAL(triggered()),this,SLOT(on_paste())); connect(cut_edit,SIGNAL(triggered()),this,SLOT(on_cut())); connect(allselect_edit,SIGNAL(triggered()),this,SLOT(on_allselect())); connect(editor,SIGNAL(textChanged()),this,SLOT(on_changed()));//當文本內容發生變化時,觸發on_changed函數 connect(comp_comp,SIGNAL(triggered()),this,SLOT(on_comp()));//當文本內容發生變化時,觸發on_changed函數 connect(run_comp,SIGNAL(triggered()),this,SLOT(on_run()));//當文本內容發生變化時,觸發on_changed函數 } void MainWindow::on_open(const QString &path) { QString fileName = path; if (fileName.isNull()) fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", "C++ Files (*.cpp *.h)"); if (!fileName.isEmpty()) { QFile file(fileName); if (file.open(QFile::ReadOnly | QFile::Text)) editor->setPlainText(file.readAll()); } } void MainWindow::setupFileMenu() { QMenu *fileMenu = new QMenu(tr("&File"),this); menuBar()->addMenu(fileMenu); //【編輯菜單欄】 edit_menu = this->menuBar()->addMenu("編輯"); copy_edit = new QAction("復制",this); copy_edit ->setShortcut(tr("ctrl+c")); edit_menu ->addAction(copy_edit); paste_edit = new QAction("粘貼",this); paste_edit ->setShortcut(tr("ctrl+v")); edit_menu ->addAction(paste_edit); cut_edit = new QAction("剪切",this); cut_edit ->setShortcut(tr("ctrl+x")); edit_menu ->addAction(cut_edit); allselect_edit = new QAction("全選",this); allselect_edit ->setShortcut(tr("ctrl+a")); edit_menu ->addAction(allselect_edit); } void MainWindow::setupEditor() { QFont font; font.setFamily("Courier"); font.setFixedPitch(true); font.setPointSize(10); editor = new QTextEdit; editor->setFont(font); QFile file("mainwindow.h"); if (file.open(QFile::ReadOnly | QFile::Text)) editor->setPlainText(file.readAll()); } void MainWindow::about() { QMessageBox::about(this, tr("About IDE"), tr("version0.0.1")); } void MainWindow::setupHelpMenu() { QMenu *helpMenu = new QMenu(tr("&Help"), this); menuBar()->addMenu(helpMenu); helpMenu->addAction(tr("&About"), this, SLOT(about())); } void MainWindow::precomp()//預編譯 { FILE *p = fopen(fileName.toStdString().data(),"r"); if(p == NULL) return ; QString cmd = fileName +".c"; FILE *p1 = fopen(cmd.toStdString().data(),"w"); if(p1 == NULL) return ; QString str; while(!feof(p)) { char buf[1024] = {0}; fgets(buf,sizeof(buf),p); str += buf; } str.replace("包含","#include"); str.replace("主函數","main"); str.replace("整數","int"); str.replace("開始","{"); str.replace("收工","}"); str.replace("。",";"); str.replace("返回","return"); str.replace("打印","printf"); str.replace("輸入輸出","<stdio.h>"); str.replace("無聲的等待...","getchar()"); fputs(str.toStdString().data(),p1); fclose(p); fclose(p1); } //程序退出 void MainWindow::on_exit() { this ->close(); } //保存文件 void MainWindow::on_save() { if(fileName.isEmpty()) { fileName = QFileDialog::getSaveFileName(this,"保存文件"); } if(!fileName.isEmpty()) { FILE *p = fopen(fileName.toStdString().data(),"w"); if(p == NULL) return ; QString str = editor->toPlainText(); fputs(str.toStdString().data(),p); fclose(p); } } //新建文件 void MainWindow::on_new() { if(is_changed == true) { on_save(); is_changed = false; } fileName = ""; editor->setText(""); } //IDE的復制功能 void MainWindow::on_copy() { editor->copy(); } void MainWindow::on_paste() { editor->paste(); } void MainWindow::on_cut() { editor->cut(); } void MainWindow::on_allselect() { editor->selectAll(); } void MainWindow::on_changed() { is_changed = true; } //編譯并運行按鈕 void MainWindow::on_comp() { if (is_changed == true)//在點擊編譯按鈕,如果文本內容發生變化,就自動保存 { on_save(); } precomp();//自動以預編譯 QString cmd; const char *s = fileName.toStdString().data(); cmd.sprintf("gcc -o %s.exe %s.c",s,s); system(cmd.toStdString().data());//先編譯 //如何刪除那個臨時文件呢 cmd = fileName.replace("/","\\") + ".c"; remove(cmd.toStdString().data()); cmd = fileName + ".exe"; system(cmd.toStdString().data());//再運行 } void MainWindow::on_run() { QString cmd; cmd = fileName + ".exe"; system(cmd.toStdString().data()); } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看