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. Slot function pointer with arguments
Qt 6.11 is out! See what's new in the release blog

Slot function pointer with arguments

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 522 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.
  • T Offline
    T Offline
    TheLumbee
    wrote on last edited by
    #1

    I'm trying to use setText() in a slot on connect without using a lambda. Here's what I have:

    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        QApplication::connect(timeThread, &QThread::started, timer, &CustomTimer::start);
        QApplication::connect(timeThread, &QThread::finished, ui->timeLabel, &QLabel::setText("Done"));
    }
    

    I'm just unsure how to call the function if it has an argument. Any guidance is appreciated.

    Thanks!

    eyllanescE 1 Reply Last reply
    0
    • T TheLumbee

      I'm trying to use setText() in a slot on connect without using a lambda. Here's what I have:

      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          QApplication::connect(timeThread, &QThread::started, timer, &CustomTimer::start);
          QApplication::connect(timeThread, &QThread::finished, ui->timeLabel, &QLabel::setText("Done"));
      }
      

      I'm just unsure how to call the function if it has an argument. Any guidance is appreciated.

      Thanks!

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @TheLumbee So create a slot:

      *.h

      private slots:
          void handle_finished();
      

      *.cpp

      void MainWindow::handle_finished(){
          ui->timeLabel->setText("Done");
      }
      

      and the connection:

      connect(timeThread, &QThread::finished, this, &MainWindow::handle_finished);
      

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      3
      • T Offline
        T Offline
        TheLumbee
        wrote on last edited by
        #3

        @eyllanesc

        Yeah, I didn't know if I needed to create a class to inherit from QLabel for that. Need to promote a label in designer but I wanted to make sure that was the simplest way.

        Thanks for the quick response!

        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