Results 1 to 5 of 5

Thread: QML Controls Feedback Problem

  1. #1
    Join Date
    Feb 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Android

    Default QML Controls Feedback Problem

    Hey,
    I have a problem with QML Controls:
    I try to connect two TextAreas via Network:
    Qt Code:
    1. TextArea{
    2. id: textarea
    3. onTextChanged: {
    4. //send message
    5. }
    6. }
    7. //onMessage:
    8. textarea.text = message;
    To copy to clipboard, switch view to plain text mode 

    The Problem is that
    Qt Code:
    1. onTextChanged
    To copy to clipboard, switch view to plain text mode 
    is although triggered if the text is set by a message. By that, a new Message is generated, which causes the generation of an other Massage on the other side an so on...

    My approach was to add a property to detect, the event was triggered manually but it won't work:
    Qt Code:
    1. TextArea{
    2. property bool surpress: false
    3. function setPassive(newText){
    4. surpress = true;
    5. text = newText;
    6. }
    7. id: textarea
    8. onTextChanged: {
    9. if(surpress){
    10. surpress = false;
    11. return;
    12. }
    13. //send message
    14. }
    15. }
    16. //onMessage:
    17. textarea.setPassive(message);
    To copy to clipboard, switch view to plain text mode 


    Any Ideas?

    best regards,
    Jakob

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QML Controls Feedback Problem

    Are you sure you want to send the full string on every change?

    Wouldn't it make more sense to have something like a "send" button?

    Cheers,
    _

  3. #3
    Join Date
    Feb 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Android

    Default Re: QML Controls Feedback Problem

    Hey,
    Thanks for your quick replay.
    Yes, I'm sure, as this TextArea is only the simplest Example. I although have the problem for example with slider.
    There I control by back-end in real-time with multiple synced clients.
    Best Regards,
    Jakob

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QML Controls Feedback Problem

    Hmm, ok.

    Your approach works for me:
    Qt Code:
    1. import QtQuick 2.4
    2. import QtQuick.Controls 1.2
    3.  
    4. Column {
    5. TextArea {
    6. id: text1
    7.  
    8. property bool ignoreNextTextChange: false
    9.  
    10. function setTextGuarded(value) {
    11. ignoreNextTextChange = true;
    12. text = value;
    13. }
    14.  
    15. onTextChanged: {
    16. if (ignoreNextTextChange) {
    17. ignoreNextTextChange = false;
    18. return;
    19. }
    20.  
    21. console.log("textChanged: " + text);
    22. }
    23. }
    24.  
    25. TextInput {
    26. text: "enter text here..."
    27. onEditingFinished: text1.setTextGuarded(text);
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Android

    Default Re: QML Controls Feedback Problem

    OK in this case it works: Here my code:

    Qt Code:
    1. import QtQuick 2.3
    2. import QtQuick.Layouts 1.1
    3. import QtQuick.Controls 1.4
    4.  
    5. ApplicationWindow {
    6. visible: true
    7. width: 640
    8. height: 480
    9. title: qsTr("Hello World")
    10.  
    11. ColumnLayout{
    12.  
    13. TextArea{
    14. id:texta1
    15. text:"text1";
    16. onTextChanged: {
    17. console.log("text1 changed");
    18. texta2.text = text;
    19. }
    20. }
    21.  
    22. TextArea{
    23. id:texta2;
    24.  
    25. onTextChanged:{
    26. console.log("text2 changed");
    27. texta1.text = text;
    28. }
    29. }
    30.  
    31. }
    32. }
    To copy to clipboard, switch view to plain text mode 

    When I do a change in a first text box, I get the following output:
    text1 changed
    text2 changed
    That's perfect. There is no recursion.

    I figured out why this works:
    We change texta1 --> it calls texta1.onTextChanged --> texta2.text is set to texta1.text --> texta2 text changed --> texta2.onTextChanged is called --> texta1.text is set to texta2.text --> texta1.text has not changed --> no Handler is called

    The problem in my case is, that the two boxes are connected via network. So when I type "ab" int the TextArea of client 1, I takes some Time, until the value ("a") is send to client to Client 2 and Client 2 sends it back to Client 1.
    But Client 1s text is already "ab", as in the main time I have typed the b. So the software begins to swing between the two values.

    In order to solve this problem and avoid this overhead feedback from client 2, I need an option to set the value of the TextArea without triggering the signal or an option to detect this feedback an block it (see my first example).

    Best regards and thanks for the ideas,
    Jakob

Similar Threads

  1. QGroupBox problem: child controls not clickable
    By zulunation in forum Qt Programming
    Replies: 5
    Last Post: 19th September 2014, 18:46
  2. Way of providing feedback
    By Momergil in forum Qwt
    Replies: 1
    Last Post: 3rd June 2014, 07:52
  3. Problem in accessing groupbox controls.
    By vani.pv in forum Newbie
    Replies: 2
    Last Post: 7th September 2012, 09:05
  4. Hiding controls changes spacing of other controls
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 18th December 2007, 21:47

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.