Call a slot in QWidget promoted class



  • I'm in a class derived from QWidget, within that my class has a slot where asks for a parameter to be passed.
    I put a widget in the GUI (Qt Designer) and took a Promote this class.
    I tried to give a connect the pushbutton onclick to the slot QWidget (ShowImage(QImage)), but can not find the slot of class I gave Promote.

    example:

    @
    connect(ui->pushButton, SIGNAL(clicked()), ui->widget, SLOT(ShowImage(QImage)));
    @

    Returns:

    QObject::connect: Incompatible sender/receiver arguments
    QPushButton::clicked() --> MyWidget::ShowImage(QImage)

    When i try:

    @
    QImage img;

    img.load("D:\\Desert.jpg");
    
    connect(ui->pushButton, SIGNAL(clicked()), ui->widget, SLOT(ShowImage(img)));
    

    @

    Object::connect: No such slot MyWidget::ShowImage(img)
    Object::connect: (sender name: 'pushButton')
    Object::connect: (receiver name: 'widget')



  • Signals and slots should have the same arguments. You can not do things like that.
    You should connect a SLOT which has no arguments, like this:
    @
    connect(ui->pushButton, SIGNAL(clicked()), ui->widget, SLOT(ShowImage()));
    @
    and modify ShouwImage method
    @
    void Widget::ShowImage()
    {
    QImage img;
    img.load("D:\Desert.jpg");
    // Show Image
    // ...
    }
    @



  • Resolved!

    I put ShowImage as a public method.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.