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. Arguments in connect with lambda expression
Forum Updated to NodeBB v4.3 + New Features

Arguments in connect with lambda expression

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

    Hello!!

    I am trying to stop a thread after a while with a QTimer::timeout(). This is my function:

    void Class::myFunction {
    	QTimer *timer = new QTimer();
    	MyThread *myThread = new MyThread();
    	myThread->start();
    	timer->start(30000);
    	connect(timer, &QTimer::timeout(), [myThread]() {myThread->stop();} );
    }
    

    Is there any possibility to do it in that connect?

    Thank you very much!!

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      @ivanicy said in Arguments in connect with lambda expression:

      &QTimer::timeout()

      This is wrong, you want the pointer to a function, not the pointer of the result of a function
      -->

      &QTimer::timeout

      See https://wiki.qt.io/New_Signal_Slot_Syntax

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • ivanicyI Offline
        ivanicyI Offline
        ivanicy
        wrote on last edited by
        #3

        Oh, what a silly mistake! Thank you very much!

        1 Reply Last reply
        1

        • Login

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