Qt信号槽连接报错:Incompatible sender/receiver arguments 问题求助
Hey there! Let's break down why you're hitting this error and how to fix it quickly.
The Root Cause
Your PbLogin button's clicked() signal doesn't send any QString parameters—there are two overloads for this signal:
void clicked()(no arguments, the one you're using)void clicked(bool checked)(only sends a boolean for toggle buttons)
But your slot Manage_User_Connexion(QString, QString) expects two string arguments. Since the signal can't pass those values to the slot, Qt throws the "incompatible arguments" error.
Solution 1: Use a Lambda Expression (Qt 5+ Recommended)
This is the cleanest approach today. You can capture your input fields (like username/password text boxes) directly in the lambda, fetch their values when the button is clicked, and pass them to your slot.
Here's how to adjust your connection code:
// Replace with your actual username/password input widget names QLineEdit* userNameInput = ui->lineEdit_UserName; QLineEdit* passwordInput = ui->lineEdit_Password; QObject::connect(PbLogin, &QPushButton::clicked, this, [this, userNameInput, passwordInput](){ QString userName = userNameInput->text(); QString password = passwordInput->text(); this->Manage_User_Connexion(userName, password); });
Bonus: Using the new pointer-based signal-slot syntax (instead of the old SIGNAL/SLOT macros) lets your compiler catch mismatches at build time, not just runtime.
Solution 2: Adjust Your Slot to Match the Signal
If you prefer sticking with the old macro syntax, you'll need to modify your slot to take no arguments, then fetch the username/password inside the slot itself.
Update your
File.hslot declaration:public slots: void Manage_User_Connexion(); // Remove the QString parametersModify the slot implementation in
file.cppto get the input values:void YourClassName::Manage_User_Connexion() { // Fetch values from your input widgets QString userName = ui->lineEdit_UserName->text(); QString password = ui->lineEdit_Password->text(); // Your original logic for handling the login goes here }Fix the signal-slot connection:
QObject::connect(PbLogin, SIGNAL(clicked()), this, SLOT(Manage_User_Connexion()));
Quick Reminder for Old Syntax
When using SIGNAL/SLOT macros, the signal and slot must have compatible argument lists:
- The signal can have more arguments than the slot (the slot can ignore extra ones)
- The slot cannot have more arguments than the signal (since the signal can't provide values for them)
内容的提问来源于stack exchange,提问作者parfait tolefo

