【发布时间】:2023-12-20 23:53:01
【问题描述】:
当我运行它时,它会立即完成并且不显示任何内容。我找不到任何错误,#qt 上也没有人可以。我有其他应用程序运行良好,所以我不确定。它与 createForm 调用有关,如果我在构造函数中省略该调用,我确实会显示默认的 QWidget。
captchit.pro
#-------------------------------------------------
#
# Project created by QtCreator 2011-02-26T20:58:23
#
#-------------------------------------------------
QT += 核心 gui 网络
目标 = 验证码 模板 = 应用程序
SOURCES += main.cpp\ 小部件.cpp
标题 += 小部件.h
main.cpp
#include "QtGui/QApplication"
#include "widget.h"
int main(int argc, char *argv[]) { QApplication a(argc, argv); 小部件 mainWidget; mainWidget.show();
return a.exec();
}
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
类 QPixmap; QLabel 类; QLineEdit 类; 类 QPushButton;
类小部件:公共 QWidget { Q_OBJECT
公开: 小部件(QWidget *parent = 0);
私人插槽: 无效 on_refreshButton_pressed(); 无效 on_submitButton_pressed(); 无效 on_closeButton_pressed();
私人: QPixmap 验证码图像; QLabel *imageLabel; QLabel *statusLabel; QLineEdit *captchaLineEdit; QPushButton *提交按钮; QPushButton *刷新按钮; QPushButton *closeButton;
void createForm();
void createActions();
void getCaptcha();
void submitCaptcha();
};
endif // WIDGET_H
widget.cpp
#include "widget.h"
#include "QtNetwork/QtNetwork"
#include "QtGui"
void Widget::on_refreshButton_pressed() { ; }
void Widget::on_submitButton_pressed() { ; }
void Widget::on_closeButton_pressed() { ; }
// 创建 UI 组件 无效小部件::createForm() { // 创建主布局 QVBoxLayout *mainLayout = new QVBoxLayout(this);
// // 将验证码像素图设置为 imageLabel 用于显示 // imageLabel->setPixmap(captchaImage);
// Create Buttons
QVBoxLayout *buttonLayout = new QVBoxLayout();
submitButton->setText("Submit");
refreshButton->setText("Refresh");
closeButton->setText("Close");
buttonLayout->addWidget(submitButton);
buttonLayout->addWidget(refreshButton);
buttonLayout->addWidget(closeButton);
// Complete Layouts
// lineEdit & submitStatus
QVBoxLayout *lineEditLayout = new QVBoxLayout();
lineEditLayout->addStretch();
lineEditLayout->addWidget(statusLabel);
lineEditLayout->addWidget(captchaLineEdit);
lineEditLayout->addStretch();
// Create Bottom Layout
QHBoxLayout *bottomLayout = new QHBoxLayout();
bottomLayout->addLayout(lineEditLayout);
bottomLayout->addLayout(buttonLayout);
// Add to mainLayout
// mainLayout->addWidget(imageLabel); mainLayout->addLayout(bottomLayout); 设置布局(主布局); }
// 绑定槽和信号 无效小部件::createActions() { ; }
void Widget::getCaptcha() { ; }
void Widget::submitCaptcha() { ; }
Widget::Widget(QWidget *parent) : QWidget(父) { 创建表单(); // createActions(); }
【问题讨论】:
-
这不是你的问题,但是为什么你有一堆带分号的空语句?