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. Chaining async calls with QFuture
Forum Updated to NodeBB v4.3 + New Features

Chaining async calls with QFuture

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 639 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.
  • H Offline
    H Offline
    hamer
    wrote on last edited by hamer
    #1

    Hi,

    Is it possible to chain async functions using QFuture chaining, e.g.:

    auto future = QtFuture::connect(reply, &QNetworkReply::finished)
    	.then([reply] {
    		return reply->readAll();
    	})
    	.then([](const QByteArray &data)
    	{
    		QTimer::singleShot(1000, this, []{
    			call next "then"
    		});
    	})
    	.then()
    	{
    		QTimer::singleShot(1000, this, []{
    			call next "then"
    		});
    	})
    	.then()
    	...
    

    Regards,

    jsulmJ Pl45m4P 2 Replies Last reply
    0
    • H hamer

      Hi,

      Is it possible to chain async functions using QFuture chaining, e.g.:

      auto future = QtFuture::connect(reply, &QNetworkReply::finished)
      	.then([reply] {
      		return reply->readAll();
      	})
      	.then([](const QByteArray &data)
      	{
      		QTimer::singleShot(1000, this, []{
      			call next "then"
      		});
      	})
      	.then()
      	{
      		QTimer::singleShot(1000, this, []{
      			call next "then"
      		});
      	})
      	.then()
      	...
      

      Regards,

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @hamer Yes. The documentation even has an example:

      QFuture<int> future = ...;
          future.then([](QFuture<int> f) {
              try {
                  ...
                  auto result = f.result();
                  ...
              } catch (QException &e) {
                  // handle the exception
              }
          }).then(...);
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • H hamer

        Hi,

        Is it possible to chain async functions using QFuture chaining, e.g.:

        auto future = QtFuture::connect(reply, &QNetworkReply::finished)
        	.then([reply] {
        		return reply->readAll();
        	})
        	.then([](const QByteArray &data)
        	{
        		QTimer::singleShot(1000, this, []{
        			call next "then"
        		});
        	})
        	.then()
        	{
        		QTimer::singleShot(1000, this, []{
        			call next "then"
        		});
        	})
        	.then()
        	...
        

        Regards,

        Pl45m4P Online
        Pl45m4P Online
        Pl45m4
        wrote on last edited by Pl45m4
        #3

        @hamer

        Why would you emit a signal and then wait for the response? If you emit a signal, you want to notify some other object and not yourself to wait (or capture the Future) again, right?
        Chaining might work (not tested nor used myself).but the way your example looks, it makes no sense

        edit:

        lol you just fixed that code :D


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        H 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @hamer

          Why would you emit a signal and then wait for the response? If you emit a signal, you want to notify some other object and not yourself to wait (or capture the Future) again, right?
          Chaining might work (not tested nor used myself).but the way your example looks, it makes no sense

          edit:

          lol you just fixed that code :D

          H Offline
          H Offline
          hamer
          wrote on last edited by
          #4

          @Pl45m4

          Yes, I updated it to make it clearer what I exactly mean.

          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