c語言入門:用qt實現簡單IDE
C語言2.79W
正在學習C語言的大家,知道用qt如何實現實現簡單IDE嗎?想是小編為大家蒐集整理出來的有關於c語言入門:用qt實現簡單IDE,希望可以幫助到大家!
123456789101112 | #include "mainwindow.h" #include <qapplication> int main( int argc, char *argv[]) {
QApplication a(argc, argv);
MainWindow w;
ze( 1000 , 800 );
();
return (); }</qapplication> |
mainwindow.h
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 | #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <qmainwindow> #include <qtextedit> #include <qmenu> #include <qmenubar> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow {
Q_OBJECT public :
explicit MainWindow(QWidget *parent = 0 );
QString file_path;
QTextEdit *te;
QMenu *file;
QMenu *edit;
QMenu *build;
QAction *open;
QAction *save;
QAction *exit_;
QAction *copy;
QAction *paste;
QAction *cut;
QAction *buildc;
QAction *run;
~MainWindow(); private :
Ui::MainWindow *ui; private slots:
void on_open_click();
void on_save_click();
void on_exit_click();
void on_copy_click();
void on_paste_click();
void on_cut_click();
void on_buildc_click();
void on_run_click(); }; #endif // MAINWINDOW_H </qmenubar></qmenu></qtextedit></qmainwindow> |
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 | #include "mainwindow.h" #include "ui_mainwindow.h" #include <stdlib.h> #include <qfiledialog> #include <qmessagebox> //#include <> MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui( new Ui::MainWindow) {
ui->setupUi( this );
te= new QTextEdit;
QFont font;
ointSize( 10 );
te->setFont(font);
this ->setCentralWidget(te);
file= new QMenu( "file" );
this ->menuBar()->addMenu(file);
edit= new QMenu( "edit" );
this ->menuBar()->addMenu(edit);
build= new QMenu( "build" );
this ->menuBar()->addMenu(build);
open= new QAction( "open" );
open->setShortcut(tr( "ctrl+o" ));
file->addAction(open);
save= new QAction( "save" );
save->setShortcut(tr( "ctrl+s" ));
file->addAction(save);
exit_= new QAction( "eixt" );
exit_->setShortcut(tr( "ctrl+q" ));
file->addAction(exit_);
connect(open,SIGNAL(triggered()), this ,SLOT(on_open_click()));
connect(save,SIGNAL(triggered()), this ,SLOT(on_save_click()));
connect(exit_,SIGNAL(triggered()), this ,SLOT(on_exit_click()));
copy= new QAction( "copy" );
copy->setShortcut(tr( "ctrl+c" ));
edit->addAction(copy);
paste= new QAction( "paste" );
paste->setShortcut(tr( "ctrl+v" ));
edit->addAction(paste);
cut= new QAction( "cut" );
cut->setShortcut(tr( "ctrl+x" ));
edit->addAction(cut);
connect(copy,SIGNAL(triggered()), this ,SLOT(on_copy_click()));
connect(paste,SIGNAL(triggered()), this ,SLOT(on_paste_click()));
connect(cut,SIGNAL(triggered()), this ,SLOT(on_cut_click()));
buildc= new QAction( "buildc" );
buildc->setShortcut(tr( "ctrl+m" ));
build->addAction(buildc);
run= new QAction( "run" );
run->setShortcut(tr( "ctrl+r" ));
build->addAction(run);
connect(buildc,SIGNAL(triggered()), this ,SLOT(on_buildc_click()));
connect(run,SIGNAL(triggered()), this ,SLOT(on_run_click())); } MainWindow::~MainWindow() {
ui;
te;
file;
edit;
build;
open;
save;
exit_;
copy;
paste;
cut;
buildc;
run; } void MainWindow::on_open_click() {
file_path=QFileDialog::getOpenFileName();
if (file_pty())
return ;
FILE *p =fopen(file_dString()(), "r" );
if (p==NULL)
{
QMessageBox::information( this , "notify" , "open file failure." );
return ;
}
QString content;
char buf[ 1024 ]={ 0 };
while (!feof(p)){
content+= fgets(buf,sizeof(buf),p);
}
fclose(p);
te->setText(content); } void MainWindow::on_save_click() {
file_path=QFileDialog::getSaveFileName();
if (file_path==NULL) return ;
FILE *p=fopen(file_dString()(), "w" );
fputs(te->toPlainText()dString()(),p);
fclose(p); } void MainWindow::on_exit_click() {
exit( 0 ); } void MainWindow::on_copy_click() {
te->copy(); } void MainWindow::on_paste_click() {
te->paste(); } void MainWindow::on_cut_click() {
te->cut(); } void MainWindow::on_buildc_click() {
QString dest=file_path;
ace( ".c" , "" );
system(( "gcc -o " + dest + " " + file_path)dString()());
QMessageBox::information( this , "notify" , "build success!" ); } void MainWindow::on_run_click() {
QString dest=file_path;
ace( ".c" , "" );
system(dString()()); } </qmessagebox></qfiledialog></stdlib.h> |
-
2017計算機二級C語言精選練習題及答案
很多時候計算機等級證書是我們找工作的敲門磚,因此,計算機等級證書也是有一定的含金量的。以下是小編為大家整理的2017計算機二級C語言精選練習題及答案,希望對大家有幫助!(1)在不同網絡結點的對等層之間的通信需要下列哪一項協議?A)模塊接口B)對等層協議C)電信號...
-
如何使用C語言求N的階乘
使用C語言求N的階乘的方法是很多小夥伴都想知道的,下面小編給大家介紹如何使用C語言求N的階乘,歡迎閲讀!如何使用C語言求N的階乘用遞歸法求N的.階乘程序調用自身稱為遞歸(recursion).它通常把一個大型複雜的問題層層轉化為一個與原問題相似的規模較小的問題來求...
-
C語言入門知識:常量
導語:在程序運行中,其值不能被改變的量稱為常量。下面是常量相關知識,歡迎閲讀:常量有5種類型:整型常量、實型常量、字符常量、字符串常量和符號常量。(一)數值轉換數字的四種表現形式:①:二進制:所有數字由0,1構成,逢二進一,二進制數中不會出現2.。例:110101②:八進制:以數...
-
C語言新人常見問題與錯誤
不知不覺,學習C語言也快一年了。雖然有C語言課,但是老師完全讓我們自己看書,在自學的過程中,和周圍同學交流中,以及後來在CSDN,BCCN,百度知道看帖回帖中,也看到許多C語言新人常遇到的問題與常犯的錯誤。不妨看看吧。以下僅供參考!對於完整的修正後的程序都在code::block...
相關文章
- A Bitter Experience in My Childhood國中英語作文
- 英語作文: The Uncivilized Internet Words
- 英語單詞詞彙知識整理:concentrate與succeed
- 關於智能的英語段落:The dull edge of intelligence
- 英語作文:Reading Outside The College
- jQuery插件擴展extend的簡單實現原理介紹
- 九年級《unit 6 I like music that I can dance to. Period2》評課稿
- 英語閲讀:VIT declines to acquire Ang Mo Kio property
- 英語閲讀:TheTwelveDancingPrincesses
- 英語滿分作文:Reading-TheBestMeanstoAcquireknowledge