Results 1 to 15 of 15

Thread: Will I learn to implement custom SIGNALS?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Unhappy Will I learn to implement custom SIGNALS?

    Reading examples and documentation I start to believe that making a custom SIGNAL is not a difficult task. Trying to do it though I realize that I cannot do it!!

    Here's a simple example, that if I understand it I will be able to make more custom signals.

    1. a line edit for number A
    2. a line edit for number B
    3. a line edit to present the result of the Multiplication


    Here is the corresponding code:


    Qt Code:
    1. MyDialog::MyDialog(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4.  
    5. QLineEdit *numberA = new QLineEdit;
    6. QLineEdit *numberB = new QLineEdit;
    7.  
    8. result = new QLineEdit;
    9.  
    10. numberA->setText("1.0");
    11. numberB->setText("1.0");
    12. result->setText("1.0");
    13.  
    14.  
    15.  
    16. vboxlayout = new QVBoxLayout(this);
    17. vboxlayout->addWidget(numberA);
    18. vboxlayout->addWidget(new QLabel("x"));
    19. vboxlayout->addWidget(numberB);
    20. vboxlayout->addWidget(new QLabel("="));
    21. vboxlayout->addWidget(result);
    22.  
    23. setLayout(vboxlayout);
    24. }
    25.  
    26.  
    27. void MyDialog::showMultiplication(QString Astring,QString Bstring)
    28. {
    29. double A,B,Res;
    30. QString ResString;
    31.  
    32.  
    33. A= Astring.toDouble();
    34. B= Bstring.toDouble();
    35.  
    36.  
    37. Res = A*B;
    38.  
    39. ResString.setNum(Res);
    40.  
    41. result->setText(ResString);
    42. }
    To copy to clipboard, switch view to plain text mode 

    QUESTION:
    When the user inserts a new number (anywhere A or B) the multiplication result should be shown directly in the result line edit. The SLOT is obliously the showMultiplication(QString Astring,QString Bstring).

    The SIGNAL should be something like
    sendNewNumbersForMultiplication(QString ,QString )

    BUT, I really cannot understand how to implement it!!
    Any help?

  2. #2
    Join Date
    Nov 2010
    Posts
    57
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Will I learn to implement custom SIGNALS?

    Maybe I miss-understand you?

    But don't you just want to declare a signal in your header file. Then emit that signal when you get a signal (whichever you choose) from the Line edit object?

    Like in your header:
    Qt Code:
    1. signals:
    2. void sendNewNumbersForMultiplication(QString ,QString );
    To copy to clipboard, switch view to plain text mode 

    Is this what you are trying to do?

  3. #3
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Will I learn to implement custom SIGNALS?

    yes, of course, I am trying to make the scenario described above to work. The user writes in a number and the system writes automatically the multiplication result in the result line edit.
    The declaration of the SIGNAL will then be as you said:
    Qt Code:
    1. signals:
    2. void sendNewNumbersForMultiplication(QString ,QString );
    To copy to clipboard, switch view to plain text mode 

    But, what will I write into the implementation of the function in the .cpp file?

    Qt Code:
    1. void MyDialog::sendNewNumbersForMultiplication(QString ,QString )
    2. {
    3.  
    4. ??
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Signals not going through to custom class.
    By GunBlade in forum Qt Programming
    Replies: 3
    Last Post: 15th August 2010, 12:50
  2. Custom Signals
    By hazardpeter in forum Qt Programming
    Replies: 6
    Last Post: 23rd July 2009, 12:09
  3. custom signals
    By talk2amulya in forum Qt Programming
    Replies: 9
    Last Post: 20th February 2009, 08:55
  4. Replies: 2
    Last Post: 19th February 2009, 19:37
  5. Custom signals?
    By godot in forum Newbie
    Replies: 7
    Last Post: 14th January 2008, 19:13

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.