c语言入门:用qt实现简单IDE
C语言2.94W
正在学习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> |
-
Mac系统怎样使用终端编写c语言程序
C语言是目前较为普遍的程序语言,它功能丰富、表达能力强、使用灵活方便、目标程序效率高,适合编制一般应用软件。下面是应届毕业生小编收集整理的Mac系统怎样使用终端编写c语言程序,希望对大家有帮助~~Mac系统使用终端编写c语言程序的'方法工具/原料Mac系统,终...
-
计算机二级C语言上机程序填空题
考虑到一部分同学的计算机二级C语言程序填空题基础比较薄弱,为此本站小编为大家整理了计算机二级C语言上机程序填空题,希望能够帮助到同学们。一、程序填空题1、给定程序中,函数fun的功能是根据形参i的值返回某个函数的值。当调用正确时,程序输出:x1=5.000000,x2=3...
-
什么是C语言中指针 C语言指针的基础使用
为什么说指针是C语言的精髓?本文主要介绍了对C语言中指针的理解与其基础使用实例,有需要的朋友可以参考一下!想了解更多相关信息请持续关注我们应届毕业生考试网!C语言的指针,关键意思在于“指”。“指”是什么意思?其实完全可以理解为指示的意思。比如,有一个物体,...
-
C语言基础知识集锦
懂编程语言,有写一些项目的`经验,能够看懂一些比较复杂项目的代码对我们是十分有帮助的,下面小编为大家整理了一些C语言基础知识,一起来看看吧:1、C语言检查是元音还是辅音#includeintmain(){charc;printf("Enteranalphabet:");scanf("%c",&c);if(c=='a'...
相关文章
- A Bitter Experience in My Childhood初中英语作文
- 关于智能的英语段落:The dull edge of intelligence
- 九年级《unit 6 I like music that I can dance to. Period2》评课稿
- 英语阅读:TheTwelveDancingPrincesses
- 英语阅读:VIT declines to acquire Ang Mo Kio property
- 英语满分作文:Reading-TheBestMeanstoAcquireknowledge
- 英语作文:Reading Outside The College
- 英语作文: The Uncivilized Internet Words
- jQuery插件扩展extend的简单实现原理介绍
- 英语单词词汇知识整理:concentrate与succeed