QT makes IDE tools for itself

Source: Internet
Author: User



Project creation

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/82/63/wKiom1dTzkCifRbzAACD5dhoxdE454.png "style=" float: none; "Title=" Project creates 1.png "alt=" Wkiom1dtzkcifrbzaacd5dhoxde454.png "/>


Base class Selection

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/82/62/wKioL1dTz0TwVXkVAABvhpBdUlE904.png "style=" float: none; "Title=" Project creates 2.png "alt=" Wkiol1dtz0twvxkvaabvhpbdule904.png "/>




Project files

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/82/63/wKiom1dTzpGChye-AAHNnhg2shY868.png "title=" Untitled. png "alt=" Wkiom1dtzpgchye-aahnnhg2shy868.png "/>





Compile run


650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/82/62/wKioL1dTz_KBNZr-AABpcDB9g-o687.png "title=" Untitled. png "alt=" Wkiol1dtz_kbnzr-aabpcdb9g-o687.png "/>




650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/82/63/wKiom1dTzwyT9ux3AABpIjS_lA4475.png "title=" Untitled. png "alt=" Wkiom1dtzwyt9ux3aabpijs_la4475.png "/>


650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/82/62/wKioL1dT0GazmZ5vAACqLfkTyQE025.png "title=" Untitled. png "alt=" Wkiol1dt0gazmz5vaacqlfktyqe025.png "/>



Project Document 1 Mainwindow.h

#ifndef  MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow> #include  <qtextedit >    //text #include <qmenu>        // Add menu #include <qmenubar>     //join menu bar #include <qaction>       //Join the menu bar #include <qfiledialog>class mainwindow : public  qmainwindow{    q_objectpublic:     mainwindow (QWidget  *parent = 0);     ~mainwindow ();p rivate:    bool  is_changed;    qstring  filename;   //the name of the current file      qtextedit *text1;   //Central TextEdit Control     //File menu      qmenu *file_menu;   //File Menu     QAction *new_file;    //new File menu item &NBSP;&Nbsp;  qaction *open_file;   //Open File menu item     qaction *save_ file;   //Save File menu item     qaction *exit_file;   //exit file     //Edit Menu     qmenu *edit_menu;   //Edit menu      qaction *copy_edit;   //Edit menu Copy button     qaction * Paste_edit;    qaction *cut_edit;    qaction *allselect_edit ;     qmenu *help_menu;   //Help menu     //compile menu      qmenu *comp_menu;   //compiling menu     qaction *comp_ comp;   //Compile button     qaction *run_comp;   //Run button      void precomp ();p rivate slots:    void on_exit ();//In the QT editing environment , install Alt+enter, prompt and press ENTER again &NBSP;    void on_open ();     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 ();}; #endif  // mainwindow_h



Project Document 2 Main.cpp

#include "mainwindow.h" #include <qapplication>int main (int argc, char *argv[]) {qapplication A (argc, argv);    MainWindow W;    W.resize (800,600);//Set the main window of the length of the width w.show (); return a.exec ();}




Project Document 3 Mainwindow.cpp

#include   "Mainwindow.h" Mainwindow::mainwindow (qwidget *parent)//Constructors     :  Qmainwindow (parent) {    text1 = new qtextedit;           //creating a Qtextedit instance in the heap     text1->setfontpointsize (14) ;     //set the font size of the form     this->setcentralwidget (Text1);   // Add the TextEdit control to the workspace of the main window     //text content changes before saving     is_changed =  false;    //add menu items and set shortcut keys for them     //"File menu bar"     file_ Menu = this->menubar ()->addmenu ("file");    new_file = new  Qaction ("New file", this);   //The first argument is the text of the menu item, and the second argument is the pointer to the body     new_file -> Setshortcut (TR ("CTRL + N"));    //set shortcut key     file_menu ->addaction (new_ file);         //Association   menu bar   and   menu item     file_menu ->addseparator ();              //display a delimiter on the file drop-down menu      open_file = new qaction ("Open File", this);    file_menu -> Addaction (Open_file),     open_file ->setshortcut (tr ("Ctrl+o"));     save_file = new qaction ("Save File", this);    file_menu -> Addaction (Save_file),     save_file ->setshortcut (tr ("Ctrl+s"));     exit_file = new qaction ("Exit", this);     file_menu ->addaction ( Exit_file);     //"Edit menu Bar"     edit_menu = this->menubar ()- >addmenu ("edit");     copy_edit = new qaction ("Copy", this);     copy_edit -> Setshortcut (TR ("CTRL + C"));     edit_menu ->addaction (Copy_edit);     paste_edit = new qaction ("Paste", this);    paste_edit -> Setshortcut (TR ("Ctrl + V"));      edit_menu ->addaction (Paste_edit);     cut_edit = new qaction ("Cut", this);    cut_edit -> Setshortcut (tr ("ctrl+x"));     edit_menu ->addaction (Cut_edit);     allselect_edit = new qaction ("Select All", this);    allselect_edit -> Setshortcut (TR ("Ctrl + A"));     edit_menu ->addaction (Allselect_edit);     //"Compiling the menu bar"     comp_menu = this->menubar ()->addMenu ("compiling");     comp_comp = new qaction ("Compile", this);  comp_menu->addaction (Comp_comp);     run_cOmp = new qaction ("Run", this);   comp_menu->addaction (Run_comp);     //"Help menu Bar"     help_menu = this->menubar ()->addmenu ("Help");     //"mouse events and Functions" when the mouse clicks the exit_file  menu, execute the on_exit () function     connect (Exit_file, SIGNAL (triggered ()), This,slot (On_exit ()));     connect (Open_file,signal ()), 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 (Text1,SIGNAL (TextChanged ()), This,slot (On_changed ()));//When text content changes, trigger on_changed function     connect (comp _comp,signal (triggered ()), This,slot (On_comp ())), or//when the text content changes, the on_changed function is triggered     connect (run _comp,signal (triggered ()), This,slot (On_run ()));//When the text content changes, the on_changed function is triggered}mainwindow::~mainwindow ()//destructor {     delete text1;    text1 = null;} Void mainwindow::p Recomp ()//Pre-compilation {    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 ("contains", "#include"),     str.replace ("Main function", "main");     Str.replace ("integer", "int"),     str.replace ("Start", "{");     str.replace ("Wrap Up" , "}");     str.replace (". ",";");     str.replace ("Back", "return"),     str.replace ("print", "printf");     str.replace ("Input Output", "<stdio.h>");     str.replace ("Silent Wait ...", " GetChar () ");     fputs (Str.tostdstring (). Data (), p1);     fclose (P);     fclose (p1);} Program Exits Void mainwindow::on_exit () {    this ->close ();} Open File Void mainwindow::on_open () {   filename = &nbsP Qfiledialog::getopenfilename (This, "open");    if (Filename.isempty ())  return ;// Consider the scenario    file *p = fopen (filename.tostdstring (). Data (), "R") that the user chooses to cancel;    if (p == null)  return ;    QString str;     while (!feof (p))     {        char buf[ 1024] = {0};        fgets (Buf,sizeof (BUF), p);         str += buf;    }     Fclose (P);     text1->settext (str);     is_changed = false;} Save File Void mainwindow::on_save () {    if (Filename.isempty ())     {         filename = qfiledialog::getsavefilename (This, "Save File") ;    }    if (!filename.isempty ())     {         file *p = fopen (Filename.tostdstring (). Data (), "W");         if (p == null)  return ;        qstring  str = text1->toplaintext ();         fputs ( Str.tostdstring (). Data (), p);         fclose (P);     }}//new File Void mainwindow::on_new () {    if (is_changed == true)      {        on_save ();         is_changed = false;    }    filename =   "";     text1->settext ("");} IDE copy function void mainwindow::on_copy () {    text1->copy ();} Void&nBsp Mainwindow::on_paste () {    text1->paste ();} Void mainwindow::on_cut () {    text1->cut ();} Void mainwindow::on_allselect () {    text1->selectall ();} Void mainwindow::on_changed () {    is_changed = true;} Compile and run the button Void mainwindow::on_comp () {    if  (is_changed == true)// Click on the Compile button, if the text content changes, automatically save     {        on_save ();     }    precomp ();//Automatic pre-compilation     QString cmd;     const char *s = filename.tostdstring (). Data ();     cmd.sprintf ("GCC&NBSP;-O&NBSP;%S.EXE&NBSP;%S.C", s,s);     system (Cmd.toStdString (). Data ());//First compile     //How to delete the temporary file     cmd = filename.replace ("/" , "\ \")  +  ". C";   &nbsP; remove (Cmd.tostdstring (). Data ());    cmd = filename +  ". exe";     system (Cmd.tostdstring (). data ());//Run}void mainwindow::on_run () {     QString cmd;    cmd = filename +  ". exe";     system (Cmd.tostdstring (). data ());



This article is from the "Soul Bucket" blog, please be sure to keep this source http://990487026.blog.51cto.com/10133282/1786270

QT makes IDE tools for itself

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.