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. Can't use initial values from a connect()
Forum Updated to NodeBB v4.3 + New Features

Can't use initial values from a connect()

Scheduled Pinned Locked Moved General and Desktop
13 Posts 6 Posters 4.7k 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.
  • EddyE Offline
    EddyE Offline
    Eddy
    wrote on last edited by
    #4

    When you use signal-slots you need the same parameters in the signal at minimum as in the slot. (you can have more in the signal than in the slot)
    otherwise the connect functionality can't give the values to the slot because there aren't any.

    in your case you need something like :
    @connect(ui->pushButton_slice, SIGNAL(mySignal(int)), this, SLOT(y_slice_extract(int ))); @

    in your mousejustpressed function you could add a signal mySignal(int) that gets its value from the position where you clicked.
    @int value = ...;
    emit mySignal(value)@

    Qt Certified Specialist
    www.edalsolutions.be

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #5

      anselmolsm is right: you can not use values in a connect statement.
      If you need to connect a signal providing no value to a slot that does require one, you can considder using a QSignalMapper instance.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jk_mk
        wrote on last edited by
        #6

        I have tried this of Everall. And I made this, but still couldn't get my result. Is it necessery to add mySignal() function as I have get my mousePressEvent() function? Could somebody help me?

        @Canvas::Canvas(): QGraphicsScene(0,0,214,256)
        {
        }

        void Canvas::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent )
        {
        emit mousejustpressed(mouseEvent->scenePos().x(),mouseEvent->scenePos().y());
        emit mySignal(mouseEvent->scenePos().y());
        }@

        @class Canvas : public QGraphicsScene
        {
        Q_OBJECT

        public:
        Canvas();

        void mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent );
        

        signals:
        void mousejustpressed(int x,int y);
        void mySignal(int y);
        };@

        @namespace Ui {
        class MainWindow;
        }

        class MainWindow : public QMainWindow
        {
        Q_OBJECT

         Canvas *scene;
        

        Canvas *scene_y;
        Canvas *scene_x;

        public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();

        private:
        Ui::MainWindow *ui;

        public slots:
        void mousejustpressed(int x,int y);
        void mySignal(int y);
        

        public slots:
        void push_button_File();
        void z_slice_extract();
        void y_slice_extract( int value);
        void x_slice_extract();

        };@
        @
        void MainWindow::mousejustpressed(int x,int y)
        {
        int k1=size_y-y;

        }

        void MainWindow::mySignal(int y)
        {
        int k1=size_y-y;
        y_slice_extract(k1);
        }@

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #7

          can you please show us the code for the connect too?

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • EddyE Offline
            EddyE Offline
            Eddy
            wrote on last edited by
            #8

            i suggested :

            bq. in your mousejustpressed function you could add a signal mySignal(int) that gets its value from the position where you clicked.
            ?
            @12 int value = ...;
            emit mySignal(value) @

            the reason why I should use this signal is because obviously you want to use the second parameter of the mousejustpressed signal.

            One of the rules in signal-slots is that you can't use the second parameter only, you also have to provide the first one.

            So an alternative could be to use 2 parameters in your connect .

            Qt Certified Specialist
            www.edalsolutions.be

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jk_mk
              wrote on last edited by
              #9

              My code for the connect is

              @connect(ui->pushButton_slice, SIGNAL(mySignal(int)), this, SLOT(y_slice_extract(int )));@

              1 Reply Last reply
              0
              • EddyE Offline
                EddyE Offline
                Eddy
                wrote on last edited by
                #10

                mySignal is not a signal of ui->pushButton_slice but belongs to "canvas"

                Hint : did you use CTRL + Spacebare to automatically find the possible choices?

                Qt Certified Specialist
                www.edalsolutions.be

                1 Reply Last reply
                0
                • EddyE Offline
                  EddyE Offline
                  Eddy
                  wrote on last edited by
                  #11

                  have you read the following?
                  "signals and slots":http://doc.qt.nokia.com/4.7-snapshot/signalsandslots.html

                  this will make everything we tried to explain to you very clear.

                  Qt Certified Specialist
                  www.edalsolutions.be

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jk_mk
                    wrote on last edited by
                    #12

                    You have right. When I change ui->pushButton_slice with scene (Canvas pointer) then I get my results when I press the mouse.Lets suppose that I have a scrollbar and I want to take the value

                    for instance.Then when I press the button I don't get the results. Do you know why?

                    I want to run the y_slice_extract(int value), every time the value of scrollbar is changed. Also, I want the event of pressing the mouse and run again the y_slice_extract(int value), with value the pixel value respectivily.

                    How this event could be done?
                    Thanks for yor link and your response

                    1 Reply Last reply
                    0
                    • EddyE Offline
                      EddyE Offline
                      Eddy
                      wrote on last edited by
                      #13

                      If i understand you well you want 2 different objects to emit a signal and catch it with a third objects slot.

                      1. connect scrollbar with y—slice—extract as we explained in another post.
                        2 ) connect pressing the mouse with y—slice—extract as we explained here

                      you can have several signals connected to the same slot. You can also connect a signal to another signal and so one. All those rules are explained in the signal slots link i gave you earlier.

                      Qt Certified Specialist
                      www.edalsolutions.be

                      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