【发布时间】:2021-12-29 13:41:45
【问题描述】:
**我发布了我想出的解决方案作为答案
我有一个学生登录用户界面,我输入登录 ID 和密码,并从我创建的 MySQL 数据库中验证它们。登录后,我需要保存输入的学生 ID 并将其发送到学生信息页面(我为学生创建的另一个 UI)。 我正在使用 QT + C++ + MySQL。 我尝试使用信号和插槽但没有结果
我的主要目标是将输入的学生 ID 发送到其他 UI。
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow){
ui->setupUi(this);
connect(ui->userIDLogin, SIGNAL(textChanged(QString)), ui->stdName ,SLOT(setText(QString))); }
它无法识别我试图将数据发送到的学生页面中的对象的 ui->stdName
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtSql>
#include <QDialog>
#include <QSqlDatabase>
#include <QMessageBox>
#include <mysql/mysql.h>
#include "student.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
public slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
Student *std;
};
struct connection_details;
MYSQL *mysql_connection_setup(struct connection_details mysql_details);
#endif // MAINWINDOW_H
这是我收到的错误消息:
This is the file error message
/home/ahmad/Desktop/DBMS project/DBMS-project-
master/mainwindow.cpp:38: error: ‘class Ui::MainWindow’ has no
member named ‘stdName’
In file included from ../DBMS project/DBMS-project-
master/student.cpp:2:
../DBMS project/DBMS-project-master/mainwindow.cpp: In constructor
‘MainWindow::MainWindow(QWidget*)’:
../DBMS project/DBMS-project-master/mainwindow.cpp:38:73: error:
‘class Ui::MainWindow’ has no member named ‘stdName’
38 | QObject::connect(ui->userIDLogin,
SIGNAL(textChanged(QString)), ui->stdName,SLOT(setText(QString)));
|
^~~~~~~
【问题讨论】:
-
那么会发生什么?任何错误信息?你看到打印出来的东西了吗?
-
在 mainwindow.cpp 中无法识别 ui->stdName,这是我要将数据发送到的对象。我将编辑问题并添加这篇文章
-
了解 Qt5 中引入的新信号/插槽连接。我敢打赌,您的连接不起作用,但这种旧样式在编译时没有提供足够的错误诊断。见wiki.qt.io/New_Signal_Slot_Syntax
-
@AhmadBader 你能复制/粘贴确切的信息吗?
-
太长了,我加到问题里了
标签: c++ qt mysql-connector