You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Qt信号槽连接报错:Incompatible sender/receiver arguments 问题求助

Fixing Qt's "Incompatible sender/receiver arguments" Error

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.


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.

  1. Update your File.h slot declaration:

    public slots:
        void Manage_User_Connexion(); // Remove the QString parameters
    
  2. Modify the slot implementation in file.cpp to 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
    }
    
  3. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 11:22:42