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. Same signal in 2 functions
Forum Updated to NodeBB v4.3 + New Features

Same signal in 2 functions

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 3.0k 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.
  • X Offline
    X Offline
    xeroblast
    wrote on last edited by
    #1

    is it possible using the same signal in 2 functions?

    @
    connect(widget1, SIGNAL(currentTextChanged(QString)), this, SLOT(function1(QString)));
    connect(widget1, SIGNAL(currentTextChanged(QString)), this, SLOT(function2(QString)));
    @

    i tried it but the 2nd function hangs-up so i was thinking if i got it right or there is something missing in my code. i must not combine the 2 functions because i want the function1() available to any widget.

    @
    connect(widget1, SIGNAL(currentTextChanged(QString)), this, SLOT(function1(QString)));
    connect(widget1, SIGNAL(currentTextChanged(QString)), this, SLOT(function2(QString)));
    connect(widget2, SIGNAL(currentTextChanged(QString)), this, SLOT(function1(QString)));
    connect(widget2, SIGNAL(currentTextChanged(QString)), this, SLOT(function3(QString)));
    @

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vishwajeet
      wrote on last edited by
      #2

      You can connect one signal to multiple slots.

      Seems some different issue here, what is going on in 2nd function ?

      Born To Code !!!

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xeroblast
        wrote on last edited by
        #3

        the 2nd function / slot just display a QBoxMessage from 1st function

        @
        QLineEdit *val;
        function1(QString data) {
        QMessageBox::information(this, "msg", "hello"); // just an identifier if this is the first to be called.
        QString result = process(data); // just processing to return a string
        val = new QLineEdit();
        val->setText(result);
        }
        function2(QString data) {
        QMessageBox::information(this, "msg", "world"); // just an identifier if this is the second to be called.
        QMessageBox::information(this, "msg", val->text());
        }
        @

        1 Reply Last reply
        0
        • ? This user is from outside of this forum
          ? This user is from outside of this forum
          Guest
          wrote on last edited by
          #4

          are you saying it didn't even show "world" dialog ?
          I'd suspect something went wrong in process(data) ....

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xeroblast
            wrote on last edited by
            #5

            i dont know if this is totally solved but my problem is fixed by changing the function type.

            before:
            @
            QString function1(QString data) {
            QString result = process(data); // just processing to return a string
            val = new QLineEdit();
            val->setText(result);
            return result;
            }
            @

            after:
            @
            void function1(QString data) {
            QString result = process(data); // just processing to return a string
            val = new QLineEdit();
            val->setText(result);
            }
            @

            i guess only void type is acceptable. correct me if i get it wrong.

            1 Reply Last reply
            0
            • X Offline
              X Offline
              xeroblast
              wrote on last edited by
              #6

              yes. the "world" dialog didnt show.

              [quote author="chetankjain" date="1298614470"]are you saying it didn't even show "world" dialog ?
              I'd suspect something went wrong in process(data) ....[/quote]

              1 Reply Last reply
              0
              • ? This user is from outside of this forum
                ? This user is from outside of this forum
                Guest
                wrote on last edited by
                #7

                [quote author="xeroblast" date="1298614555"]i guess only void type is acceptable. correct me if i get it wrong.[/quote]

                Not correct. The return type can be anything.

                Some inconsistency, in your earlier example you posted code for methods called function1 and function2 and in the most recent code snip its ... QString function1(..) and void function1(..)?

                1 Reply Last reply
                0
                • X Offline
                  X Offline
                  xeroblast
                  wrote on last edited by
                  #8

                  [quote author="chetankjain" date="1298614808"]
                  Some inconsistency, in your earlier example you posted code for methods called function1 and function2 and in the most recent code snip its ... QString function1(..) and void function1(..)?
                  [/quote]

                  im sorry, i forgot to put the QString type in the function1() and function2() is a void in my previous code.

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    vishwajeet
                    wrote on last edited by
                    #9

                    Still it does not make sense that why second function would hang.

                    is it possible for u to paste complete code which hangs ?

                    Born To Code !!!

                    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