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. Custom signal to slot : The slot requires more arguments than the signal provides.

Custom signal to slot : The slot requires more arguments than the signal provides.

Scheduled Pinned Locked Moved Solved General and Desktop
signals slotslambda
15 Posts 4 Posters 6.1k 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.
  • M mrjj
    27 Feb 2018, 23:04

    @Petross404_Petros-S
    Hi
    You would have to hook up the old signal to private slot and
    emit your new signal with the "this" pointer in that slot since you want to change what is
    emitted.

    If dice is using QMovie, it would be fine if it had it as a private member as then
    its very self contained.

    P Offline
    P Offline
    Petross404_Petros S
    wrote on 27 Feb 2018, 23:07 last edited by
    #6

    @mrjj

    Hmm, I haven't thought of the old syntax. Thank you, I will test tomorrow morning and report any findings.

    M 1 Reply Last reply 27 Feb 2018, 23:09
    0
    • P Petross404_Petros S
      27 Feb 2018, 23:07

      @mrjj

      Hmm, I haven't thought of the old syntax. Thank you, I will test tomorrow morning and report any findings.

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 27 Feb 2018, 23:09 last edited by mrjj
      #7

      @Petross404_Petros-S
      Not the old syntax, the old signal frameChanged.
      You would bind it to a private slot and
      void MyMovie::FrameChanged() {
      emit MynewFrameChanged(this);
      }

      But please check if move could just be in Dice as its the main user and
      should just have the object then.

      P 1 Reply Last reply 27 Feb 2018, 23:50
      0
      • M mrjj
        27 Feb 2018, 23:09

        @Petross404_Petros-S
        Not the old syntax, the old signal frameChanged.
        You would bind it to a private slot and
        void MyMovie::FrameChanged() {
        emit MynewFrameChanged(this);
        }

        But please check if move could just be in Dice as its the main user and
        should just have the object then.

        P Offline
        P Offline
        Petross404_Petros S
        wrote on 27 Feb 2018, 23:50 last edited by
        #8

        @mrjj OK before powering off my pc, I thought let's try to declare QMovie* movie as a private member of QtDice.

        Afterwards, just before using the movie, I setted the filename movie.setfilename(":/images/etc") but the compiler ranted something about static variable movie but I am quite sleepy to remember.

        Perhaps I must also use new somehow on an existing variable to actually create it. I think I found what I will be looking the next day.

        All the best, Petros.

        M 1 Reply Last reply 27 Feb 2018, 23:54
        0
        • P Petross404_Petros S
          27 Feb 2018, 23:50

          @mrjj OK before powering off my pc, I thought let's try to declare QMovie* movie as a private member of QtDice.

          Afterwards, just before using the movie, I setted the filename movie.setfilename(":/images/etc") but the compiler ranted something about static variable movie but I am quite sleepy to remember.

          Perhaps I must also use new somehow on an existing variable to actually create it. I think I found what I will be looking the next day.

          All the best, Petros.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 27 Feb 2018, 23:54 last edited by mrjj
          #9

          @Petross404_Petros-S
          Yes , yes you MUST new it in QtDice constructor before use.
          (movie = new QMovie(this) )

          and its
          movie ->setfilename not the . (dot) syntax :)
          (-> for pointers DOt is for non pointers)

          1 Reply Last reply
          2
          • P Offline
            P Offline
            Petross404_Petros S
            wrote on 28 Feb 2018, 11:35 last edited by
            #10

            Yes , yes you MUST new it in QtDice constructor before use.

            Actually, when I new it in QtDice::QtDice I get a segfault when I try to set it's filename in the slot void QtDice::image_update(int) .

            The moment I write in the latter, QMovie movie = new QMovie(this) and afterwards set the filename, it works.

            Anyway that isn't Qt specific anymore but about my lack of proper C++ understanding. I will keep this for a little longer UNSOLVED and will post any findings to close it. Thank you very much.

            1 Reply Last reply
            0
            • V Offline
              V Offline
              VRonin
              wrote on 28 Feb 2018, 12:21 last edited by
              #11

              connect(movie, &QMovie::frameChanged, this, std::bind(&QtDice::qmovieFrameChanged,this,movie));

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              3
              • M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 28 Feb 2018, 12:27 last edited by
                #12

                hi
                My guess is that u do the classic error/facepalm
                QMovie movie = new QMovie(this) ; // this make a LOCAL variable. not what u want
                To use the one from .h
                movie = new QMovie(this); // NOTICE No TYPE FIRST. we set the member to something.

                1 Reply Last reply
                3
                • P Offline
                  P Offline
                  Petross404_Petros S
                  wrote on 28 Feb 2018, 16:27 last edited by Petross404_Petros S
                  #13

                  @VRonin

                  Indeed that worked! Compiler didn't warn about anything and as a matter of fact I was thinking of QSignalMapper and std::bind but thought it would be very complex. It's a chance to take a closer look at your code and practice on toy-programs with bind.

                  Anyway, with your solution I don't need a lambda for this anymore.

                  @mrjj

                  In the ctror I wrote movie = new QMovie(this) but there is another problem. Now that I use a private class member movie, the animation doesn't play. The gif is shown, but it's frozen. It doesn't matter if I use std::bind as VRonin proposed or if I use the lambda.

                  As long as the QMovie is created in the ctor like this :

                  // In the ctor
                  movie = new QMovie(this);
                  movie->setFileName(":/images/rolling_infinite.gif");
                  ...
                  //In void QtDice::image_update(int image_number)
                  ....
                  m_ui->label->setMovie(movie);
                  //Animation works!
                  

                  But I set the movie's filename inside the function :

                  // In the ctor
                  movie = new QMovie(this);
                  ....
                  // In the void QtDice::image_update(int image_number)
                  movie->setFileName(":/images/rolling_infinite.gif");
                  m_ui->label->setMovie(movie);
                  
                  if(movie->isValid())
                  {
                  //again is valid is printed, Qt continues to accept movie as valid.
                  	qDebug() << "is valid" << '\n';
                  	movie->start();
                  }
                  else...
                  //Gif is shown, but doesn't animate
                  

                  I even tried to append this-> infront of movie but of course this wasn't the problem. It can access the variable as there isn't any movie in scope. I can drop the issue here because the custom signal to signal connection is accomplished, but I want to know how to debug the stopped animation problem. GUI isn't unresponsive, I guess it's not a crash...

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 28 Feb 2018, 17:19 last edited by mrjj
                    #14

                    Hi
                    it really should work the same as in ctor.
                    Must be something else.
                    In what function is example 2 ?

                    1 Reply Last reply
                    1
                    • P Offline
                      P Offline
                      Petross404_Petros S
                      wrote on 28 Feb 2018, 19:17 last edited by Petross404_Petros S
                      #15

                      @mrjj It goes like this :

                      Ctor connects a pushbutton click with QtDice::reload which in turn calls QtDice::image_update to animate the gif and after it's finished, show an image.

                      I found out what the problem is. QtDice::image_update is called multiple times and therefore it tries to setFileName every time. So a check if fileName() is empty must be done each time before attempting to setFileName.

                      void QtDice::image_update(int image_number)
                      {
                      	//Make sure we don't constantly re-append a fileName!
                      	if(movie->fileName() == "" )
                      	{
                      		movie->setFileName(":/images/rolling_infinite.gif");
                      		
                      		//If it still is empty print error and exit. Not good at all
                      		//TODO wrap the setFileName in some Qt assert to throw an exception
                      		if (movie->fileName() == "")
                      		{
                      			qDebug() << "Error! Couldn't set a fileName to read for the animation";
                      			QApplication::quit();
                      		}
                      	}
                      	
                      	m_ui->label->setMovie(movie);
                      	.....
                      }
                      

                      I don't know exactly why this failed ( I mean I could change the fileName as many times as I like), but I checked and rechecked that with this if (movie->fileName() == "" ).... the animation works.

                      That could also explain why some (but not all) times the animation played the very first time I push the button (ie called the function) and the second time it stopped. If someone thinks that other reasons come into play, please inform me, I am more than glad to learn.

                      For any of you, that is curious what is the code and/or want to c&c, this is the QtDice and this is a screenshot

                      Have a nice afternoon!

                      1 Reply Last reply
                      0

                      15/15

                      28 Feb 2018, 19:17

                      • Login

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