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. Function with Signals & Slots
Forum Updated to NodeBB v4.3 + New Features

Function with Signals & Slots

Scheduled Pinned Locked Moved Solved General and Desktop
functionsignal & slot
38 Posts 6 Posters 9.8k Views 4 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.
  • jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #11

    The thing is:

    connect (Image_Button,SIGNAL(clicked(bool)),this,SLOT(findimage(bool)));
    qDebug() <<"The image path is (in main): " << fileName;
    
    • it doesn't matter where fileName (or m_fileName) is declared, after the connect(...) call it will not be set yet because the findimage(bool) slot was not yet called. It will be called when the user clicks on the button - and you never know when the user will click the button.

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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gabor53
      wrote on last edited by
      #12

      Thank you all. Now I understand what's wrong. After the user clicks Image_Button, I want to display the image in a grid layout in which the Image_Button is. Is there a way I can go back to the grid layout AFTER the user clicked Image_Button and insert the choosen image next to the button?

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #13

        Hi if u use @JordanHarris smart version,
        you could do something like
        connect(imageButton, &QPushButton::clicked, this {
        imagePath = findImage();
        QPixmap pic(imagePath);
        ui->SomeQLabel->setPixmap(pic);
        });

        you must insert the "SomeQLabel" into the layout. (just a normal Qlabel)

        G 1 Reply Last reply
        1
        • mrjjM mrjj

          Hi if u use @JordanHarris smart version,
          you could do something like
          connect(imageButton, &QPushButton::clicked, this {
          imagePath = findImage();
          QPixmap pic(imagePath);
          ui->SomeQLabel->setPixmap(pic);
          });

          you must insert the "SomeQLabel" into the layout. (just a normal Qlabel)

          G Offline
          G Offline
          gabor53
          wrote on last edited by
          #14

          @mrjj ,
          I implemented

          connect(Image_Button, &QPushButton::clicked, [this]() { imagePath = findimage(); })
          

          and I got the following error message:
          C:\Programming\backup\Folkfriends\additem.cpp:195: error: no match for 'operator=' (operand types are 'QString' and 'void')
          connect(Image_Button, &QPushButton::clicked, this { imagePath = findimage(); });
          ^
          I'm wondering what am I missing.

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #15

            well basically it says you are doing
            void = QString
            so check that findimage returns Qstring and that
            imagePath is also declared Qstring

            G 1 Reply Last reply
            0
            • mrjjM mrjj

              well basically it says you are doing
              void = QString
              so check that findimage returns Qstring and that
              imagePath is also declared Qstring

              G Offline
              G Offline
              gabor53
              wrote on last edited by
              #16

              @mrjj
              I did that. Now it says
              C:\Programming\backup\Folkfriends\additem.cpp:195: error: expected primary-expression before ')' token
              connect(Image_Button, &QPushButton::clicked, this { imagePath = findimage(QString); });
              ^

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #17

                Does ur compiler support lambdas?
                Try with empty { }

                connect(Image_Button, &QPushButton::clicked, [this]() {  })
                

                you need Qt 5.5 and newer compiler.

                G 1 Reply Last reply
                0
                • mrjjM mrjj

                  Does ur compiler support lambdas?
                  Try with empty { }

                  connect(Image_Button, &QPushButton::clicked, [this]() {  })
                  

                  you need Qt 5.5 and newer compiler.

                  G Offline
                  G Offline
                  gabor53
                  wrote on last edited by
                  #18

                  @mrjj
                  How can I find out if it supports lambdas?

                  mrjjM 1 Reply Last reply
                  0
                  • G gabor53

                    @mrjj
                    How can I find out if it supports lambdas?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #19

                    @gabor53
                    well it can then compile the line.
                    what compiler is it ?
                    VS or mingw?
                    and what version?

                    G 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @gabor53
                      well it can then compile the line.
                      what compiler is it ?
                      VS or mingw?
                      and what version?

                      G Offline
                      G Offline
                      gabor53
                      wrote on last edited by
                      #20

                      @mrjj
                      I have mingw 4.9.2 32 bit

                      mrjjM 1 Reply Last reply
                      0
                      • G gabor53

                        @mrjj
                        I have mingw 4.9.2 32 bit

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by mrjj
                        #21

                        @gabor53
                        ahh, u might need
                        CONFIG+=c++11
                        in your .pro file for it to use c++ 11 :)

                        G 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @gabor53
                          ahh, u might need
                          CONFIG+=c++11
                          in your .pro file for it to use c++ 11 :)

                          G Offline
                          G Offline
                          gabor53
                          wrote on last edited by
                          #22

                          @mrjj
                          I have that too, so I guess it supports lambdas.

                          kshegunovK 1 Reply Last reply
                          0
                          • G gabor53

                            @mrjj
                            I have that too, so I guess it supports lambdas.

                            kshegunovK Offline
                            kshegunovK Offline
                            kshegunov
                            Moderators
                            wrote on last edited by
                            #23

                            @gabor53
                            It's not the lambda.

                            imagePath = findimage(QString);

                            This doesn't make sense neither to the compiler nor to me, so you should fix it. What argument are you trying to use findimage with? Currently it has none, and instead of an argument a type name is provided.

                            Kind regards.

                            Read and abide by the Qt Code of Conduct

                            mrjjM 1 Reply Last reply
                            2
                            • kshegunovK kshegunov

                              @gabor53
                              It's not the lambda.

                              imagePath = findimage(QString);

                              This doesn't make sense neither to the compiler nor to me, so you should fix it. What argument are you trying to use findimage with? Currently it has none, and instead of an argument a type name is provided.

                              Kind regards.

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #24

                              @kshegunov
                              ahh good spotted. thats the void = QString :)
                              I completely missed that .)

                              kshegunovK 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                @kshegunov
                                ahh good spotted. thats the void = QString :)
                                I completely missed that .)

                                kshegunovK Offline
                                kshegunovK Offline
                                kshegunov
                                Moderators
                                wrote on last edited by kshegunov
                                #25

                                @mrjj
                                I just read the compiler errors, it says it right there:

                                expected primary-expression before ')' token

                                ;)

                                Read and abide by the Qt Code of Conduct

                                mrjjM 1 Reply Last reply
                                0
                                • kshegunovK kshegunov

                                  @mrjj
                                  I just read the compiler errors, it says it right there:

                                  expected primary-expression before ')' token

                                  ;)

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #26

                                  @kshegunov
                                  yeah it's a meaningful and good compiler error :)

                                  1 Reply Last reply
                                  1
                                  • L Offline
                                    L Offline
                                    Lineaxe
                                    wrote on last edited by
                                    #27

                                    Heheh, of course that's right. I gotta get back to programming again, I been installing , upgrading and reading too much...
                                    ** it doesn't matter where fileName (or m_fileName) is declared, after the connect(...) call it will not be set yet because the findimage(bool) slot was not yet called. It will be called when the user clicks on the button - and you never know when the user will click the button. **

                                    1 Reply Last reply
                                    0
                                    • G Offline
                                      G Offline
                                      gabor53
                                      wrote on last edited by
                                      #28

                                      I changed the following line:

                                             connect(Image_Button, &QPushButton::clicked, [this]() { imagePath =  findimage( QString);});
                                      
                                      to 
                                      
                                         connect(Image_Button, &QPushButton::clicked, [this]() { imagePath =  findimage( fileName);});
                                      
                                      Now I get the following error message:
                                      C:\Programming\backup\Folkfriends\additem.cpp:195: error: no match for 'operator=' (operand types are 'QString' and 'void')
                                              connect(Image_Button, &QPushButton::clicked, [this]() { imagePath =  findimage( fileName);});
                                                                                          
                                      What else to change? Thank you.
                                      1 Reply Last reply
                                      0
                                      • mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by mrjj
                                        #29

                                        Hi
                                        in the first post you show it as
                                        findimage(bool)

                                        so that would be callable as
                                        imagePath = findimage( true);

                                        So what you give it as parameter, depends on how u declare it.
                                        (in the .h file)

                                        G 1 Reply Last reply
                                        0
                                        • mrjjM mrjj

                                          Hi
                                          in the first post you show it as
                                          findimage(bool)

                                          so that would be callable as
                                          imagePath = findimage( true);

                                          So what you give it as parameter, depends on how u declare it.
                                          (in the .h file)

                                          G Offline
                                          G Offline
                                          gabor53
                                          wrote on last edited by
                                          #30

                                          @mrjj
                                          I changed it from findimage(bool) to findimage(fileName) because I need it to return the fileName.
                                          In the .h file it is defined as void findimage(QString fileName);
                                          I still have the same error message. Thank you.

                                          mrjjM 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