Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Call a slot in QWidget promoted class
Forum Updated to NodeBB v4.3 + New Features

Call a slot in QWidget promoted class

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    beowulf
    wrote on last edited by
    #1

    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')

    -- 0x00

    1 Reply Last reply
    0
    • B Offline
      B Offline
      beemaster
      wrote on last edited by
      #2

      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
      // ...
      }
      @

      1 Reply Last reply
      0
      • B Offline
        B Offline
        beowulf
        wrote on last edited by
        #3

        Resolved!

        I put ShowImage as a public method.

        -- 0x00

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved