关于QT Creator不能使用代码提示功能

关于QT Creator 4.9.1版本不能使用代码提示功能

在安装使用QT Creator 4.9.1版本后,发现除了#include可以代码提示,代码其他位置的函数或者其他变量等都不能通过代码提示来补全,使用很麻烦。一开始我查看工具–>选项–>环境–>键盘中的TextEditor–>CompleteThis的默认快捷键是Ctrl+空格,网上说这个和输入法的快捷键冲突的,我将其改成Ctrl+Right(改成自己习惯的就行~),还是不行。
最后发现是帮助–>关于插件下的已安装的插件的原因。
已安装插件
其中在C++ 下有个 ClangCodeModel插件将其关闭,需要重启QT Creator,再次敲代码的过程中按下Ctrl+Right(根据自己的快捷键设置),代码提示就出来了,问题解决~

  • 28
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
运用Qt开发工具来实现一个记事本,用户图形界面操作,通过Qt提供的图形库来设计记事本的管理、应用基本窗口,主要实现打开、新建、保存、另存为、查找、居中、字体、颜色等功能设计,同时在软件内部实现对于这些功能的支持和实现。还有对用户剪切、复制、粘贴、等功能的支持 核心代码讲解 1、打开文件功能 void MainWindow::on_action_2_triggered() { QString filename = QFileDialog::getOpenFileName(this); loadFile(filename); } 打开文件on_action_2_triggered()通过转到槽实现首先定义一个Qstring类型的filename让它获取你文件名,其次寻找它的本地连接。 3、保存文件功能 void MainWindow::on_action_3_triggered() { if(isSaved){ saveFile(curFile); } else{ do_file_SaveAS(); } } 保存文件功能on_action_3_triggered()通过转到槽实现,先判断bool型的isSaved是否是正确的,如果错则保存当前文件,否则执行另存为。 5、关闭功能 void MainWindow::on_action_5_triggered() { if(close){ QMessageBox::information(this,"提示","文件尚未保存,关闭"); }else{ ui->textEdit->close(); } } 关闭功能on_action_5_triggered()先对文本进行判断是否是关闭的,如果是错弹对话框提示消息文件尚未保存,关闭,否则对文档进行关闭 11、查找功能 //查找 void MainWindow::close_findhangshu() { ui->gridLayoutWidget->close(); } close_findhangshu()对查找对话框进行关闭函数。 void MainWindow::on_action_11_triggered() { QDialog *closefind=new QDialog(this); QDialog *findDlg=new QDialog(this); find_textLineEdit=new QLineEdit(findDlg); QPushButton *find_Bth=new QPushButton(tr("查找下一个"),findDlg); QPushButton *close_find=new QPushButton(tr("关闭"),closefind); ui->gridLayout->addWidget(find_textLineEdit); ui->gridLayout->addWidget(find_Bth); ui->gridLayout->addWidget(close_find); connect(find_Bth,SIGNAL(clicked()),this,SLOT(show_findText())); connect(close_find,SIGNAL(clicked()),this,SLOT(close_findhangshu())); } 查找功能on_action_11_triggered()函数通过转到槽实现下面部分:先定义两个QDialog类型 指针变量*closefind和*findDlg,对它们进行新创建空间, find_textLineEdit=new QLineEdit(findDlg);新建一个空间对QlineEdit它进行传参,将findDlg传入目的是查找在文档中对应的文字,QPushButton *find_Bth=new QPushButton(tr("查找下一个"),findDlg);QPushButton *close_find=new QPushButton(tr("关闭"),closefind);这两个代码作用相同定义两个Qpubutton当点击查找功能对话框时在对话框中实现查找下一个和关闭connect(find_Bth,SIGNAL(clicked()),this,SLOT(show_findText()));connect(close_find,SIGNAL(clicked()),this,SLOT(close_findhangshu()));点击查找下一个按钮时对它进行连接,执行show_findText()函数中的查找操作,如果点击关闭执行上述所说的close_findhangshu()关闭对话框操作 void MainWindow:: show_findText() { QString findText=find_textLineEdit->text(); if(!ui->textEdit->find(findText,QTextDocument::FindBackward)) { QMessageBox::warning(this,tr("查找"),tr("找不到 %1").arg(findText)); } } show_findText()此函数先定义QString类型 findText值,对文本进行扫描,如果文本不能找到找到则提示找不到。 本人也只是一个学生,记得点赞哦!
首先需要安装Qt CreatorQt库。安装完成后,可以按照以下步骤进行实现: 1. 新建Qt Widgets Application项目。 2. 在项目中添加四个Label和一个PushButton,用于显示游戏界面和重新开始游戏。 3. 编写游戏逻辑代码,实现游戏的初始化、移动、合并等操作。 4. 将游戏逻辑代码与界面进行连接,实现游戏的展示和操作。 5. 编写结束判断代码,当游戏结束时弹游戏结束提示框。 6. 部署程序,生成可执行文件。 下面是一个简单的2048实现示例代码: mainwindow.h文件: ```cpp #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QLabel> #include <QPushButton> class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: QLabel *box[4][4]; QPushButton *restartBtn; int score; bool gameover; void initGame(); void clearBox(); void newBox(); void updateBox(); void moveLeft(); void moveRight(); void moveUp(); void moveDown(); bool canMove(); bool canCombine(); bool isGameOver(); void gameOver(); int getRand(int min, int max); private slots: void restartGame(); void keyPressEvent(QKeyEvent *event); }; #endif // MAINWINDOW_H ``` mainwindow.cpp文件: ```cpp #include "mainwindow.h" #include "ui_mainwindow.h" #include <QKeyEvent> #include <QMessageBox> #include <ctime> #include <cstdlib> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // 设置窗口大小 setFixedSize(400, 400); // 新建重新开始按钮 restartBtn = new QPushButton(this); restartBtn->setText("重新开始"); restartBtn->setGeometry(290, 30, 100, 30); connect(restartBtn, SIGNAL(clicked(bool)), this, SLOT(restartGame())); // 新建游戏盒子 for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { box[i][j] = new QLabel(this); box[i][j]->setGeometry(20 + i * 90, 100 + j * 90, 80, 80); box[i][j]->setStyleSheet("background-color: #bbada0; border-radius: 5px; font-size: 36px; font-weight: bold; color: #776e65; text-align: center;"); box[i][j]->setText(""); } } // 初始化游戏 initGame(); } MainWindow::~MainWindow() { } void MainWindow::initGame() { // 清空游戏盒子 clearBox(); // 初始化得分和游戏状态 score = 0; gameover = false; // 新建两个数字盒子 newBox(); newBox(); // 更新游戏盒子 updateBox(); } void MainWindow::clearBox() { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { box[i][j]->setText(""); } } } void MainWindow::newBox() { int i, j; do { i = getRand(0, 3); j = getRand(0, 3); } while (box[i][j]->text() != ""); int value = getRand(1, 2) * 2; box[i][j]->setText(QString::number(value)); } void MainWindow::updateBox() { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { int value = box[i][j]->text().toInt(); if (value == 0) { box[i][j]->setText(""); } else { box[i][j]->setText(QString::number(value)); } switch (value) { case 0: box[i][j]->setStyleSheet("background-color: #bbada0; border-radius: 5px; font-size: 36px; font-weight: bold; color: #776e65; text-align: center;"); break; case 2: box[i][j]->setStyleSheet("background-color: #eee4da; border-radius: 5px; font-size: 36px; font-weight: bold; color: #776e65; text-align: center;"); break; case 4: box[i][j]->setStyleSheet("background-color: #ede0c8; border-radius: 5px; font-size: 36px; font-weight: bold; color: #776e65; text-align: center;"); break; case 8: box[i][j]->setStyleSheet("background-color: #f2b179; border-radius: 5px; font-size: 36px; font-weight: bold; color: #f9f6f2; text-align: center;"); break; case 16: box[i][j]->setStyleSheet("background-color: #f59563; border-radius: 5px; font-size: 36px; font-weight: bold; color: #f9f6f2; text-align: center;"); break; case 32: box[i][j]->setStyleSheet("background-color: #f67c5f; border-radius: 5px; font-size: 36px; font-weight: bold; color: #f9f6f2; text-align: center;"); break; case 64: box[i][j]->setStyleSheet("background-color: #f65e3b; border-radius: 5px; font-size: 36px; font-weight: bold; color: #f9f6f2; text-align: center;"); break; case 128: box[i][j]->setStyleSheet("background-color: #edcf72; border-radius: 5px; font-size: 36px; font-weight: bold; color: #f9f6f2; text-align: center;"); break; case 256: box[i][j]->setStyleSheet("background-color: #edcc61; border-radius: 5px; font-size: 36px; font-weight: bold; color: #f9f6f2; text-align: center;"); break; case 512: box[i][j]->setStyleSheet("background-color: #edc850; border-radius: 5px; font-size: 36px; font-weight: bold; color: #f9f6f2; text-align: center;"); break; case 1024: box[i][j]->setStyleSheet("background-color: #edc53f; border-radius: 5px; font-size: 36px; font-weight: bold; color: #f9f6f2; text-align: center;"); break; case 2048: box[i][j]->setStyleSheet("background-color: #edc22e; border-radius: 5px; font-size: 36px; font-weight: bold; color: #f9f6f2; text-align: center;"); break; default: box[i][j]->setStyleSheet("background-color: #3c3a32; border-radius: 5px; font-size: 36px; font-weight: bold; color: #f9f6f2; text-align: center;"); break; } } } } void MainWindow::moveLeft() { bool flag = false; for (int i = 0; i < 4; i++) { int last = -1; for (int j = 0; j < 4; j++) { if (box[i][j]->text() == "") { continue; } if (last == -1) { last = j; } else { if (box[i][last]->text() == box[i][j]->text()) { int value = box[i][j]->text().toInt() * 2; score += value; box[i][last]->setText(QString::number(value)); box[i][j]->setText(""); last = -1; flag = true; } else { last = j; } } } if (last != -1) { if (last != i) { box[i][last]->setText(box[i][i]->text()); box[i][i]->setText(""); flag = true; } } } if (flag) { newBox(); updateBox(); } } void MainWindow::moveRight() { bool flag = false; for (int i = 0; i < 4; i++) { int last = -1; for (int j = 3; j >= 0; j--) { if (box[i][j]->text() == "") { continue; } if (last == -1) { last = j; } else { if (box[i][last]->text() == box[i][j]->text()) { int value = box[i][j]->text().toInt() * 2; score += value; box[i][last]->setText(QString::number(value)); box[i][j]->setText(""); last = -1; flag = true; } else { last = j; } } } if (last != -1) { if (last != i) { box[i][last]->setText(box[i][i]->text()); box[i][i]->setText(""); flag = true; } } } if (flag) { newBox(); updateBox(); } } void MainWindow::moveUp() { bool flag = false; for (int j = 0; j < 4; j++) { int last = -1; for (int i = 0; i < 4; i++) { if (box[i][j]->text() == "") { continue; } if (last == -1) { last = i; } else { if (box[last][j]->text() == box[i][j]->text()) { int value = box[i][j]->text().toInt() * 2; score += value; box[last][j]->setText(QString::number(value)); box[i][j]->setText(""); last = -1; flag = true; } else { last = i; } } } if (last != -1) { if (last != j) { box[last][j]->setText(box[j][j]->text()); box[j][j]->setText(""); flag = true; } } } if (flag) { newBox(); updateBox(); } } void MainWindow::moveDown() { bool flag = false; for (int j = 0; j < 4; j++) { int last = -1; for (int i = 3; i >= 0; i--) { if (box[i][j]->text() == "") { continue; } if (last == -1) { last = i; } else { if (box[last][j]->text() == box[i][j]->text()) { int value = box[i][j]->text().toInt() * 2; score += value; box[last][j]->setText(QString::number(value)); box[i][j]->setText(""); last = -1; flag = true; } else { last = i; } } } if (last != -1) { if (last != j) { box[last][j]->setText(box[j][j]->text()); box[j][j]->setText(""); flag = true; } } } if (flag) { newBox(); updateBox(); } } bool MainWindow::canMove() { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (box[i][j]->text() == "") { return true; } if (i > 0 && box[i][j]->text() == box[i - 1][j]->text()) { return true; } if (i < 3 && box[i][j]->text() == box[i + 1][j]->text()) { return true; } if (j > 0 && box[i][j]->text() == box[i][j - 1]->text()) { return true; } if (j < 3 && box[i][j]->text() == box[i][j + 1]->text()) { return true; } } } return false; } bool MainWindow::canCombine() { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (i > 0 && box[i][j]->text() == box[i - 1][j]->text()) { return true; } if (i < 3 && box[i][j]->text() == box[i + 1][j]->text()) { return true; } if (j > 0 && box[i][j]->text() == box[i][j - 1]->text()) { return true; } if (j < 3 && box[i][j]->text() == box[i][j + 1]->text()) { return true; } } } return false; } bool MainWindow::isGameOver() { if (canMove()) { return false; } if (canCombine()) { return false; } return true; } void MainWindow::gameOver() { gameover = true; QMessageBox::information(this, "游戏结束", "得分:" + QString::number(score)); } int MainWindow::getRand(int min, int max) { srand(time(NULL)); return rand() % (max - min + 1) + min; } void MainWindow::restartGame() { initGame(); } void MainWindow::keyPressEvent(QKeyEvent *event) { if (gameover) { return; } switch (event->key()) { case Qt::Key_Left: moveLeft(); if (isGameOver()) { gameOver(); } break; case Qt::Key_Right: moveRight(); if (isGameOver()) { gameOver(); } break; case Qt::Key_Up: moveUp(); if (isGameOver()) { gameOver(); } break; case Qt::Key_Down: moveDown(); if (isGameOver()) { gameOver(); } break; default: break; } } ``` 编译运行后,即可在窗口中玩2048游戏。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值