Results 1 to 10 of 10

Thread: How to write a program to show 64bit hex with checkbox?

  1. #1
    Join Date
    Mar 2015
    Posts
    24
    Thanks
    20
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Lightbulb How to write a program to show 64bit hex with checkbox?

    Hi
    I'm trying to write a program to show a 64bit hex value or less than 64bit as 64 checkbox. the GUI is this:



    the scenario:

    when you put a hex value in the lineEdit, it should show us the changes in the checkboxes. please note that each checkbox is as a bit in order number.
    or when check or uncheck the checkboxes, it should show us the changes in the lineEdit.

    now the question is how to write this? I think I have to choose a special slot for lineEdit. how about textChanged() slot? should I use it? and what for checkboxes?

    Any idea?

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to write a program to show 64bit hex with checkbox?

    One possible solution is to convert the text to 64 bit integer on each "textChanged()" and check/uncheck each checkBox according to the bit value in the number. Adding all checkBoxes to a list makes thing simple:
    Qt Code:
    1. void MyWidget::textChanged(const QString& text){
    2. const qint64 value = text.toInt64();
    3. for (int i=0 ; i<64 ; ++i){
    4. this->m_checkBoxList[i]->setChecked( test_bit(value,i) );
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 
    implementing "test_bit(qint64 value, int bitIndex)" to check a single bit in number is left as an excercise
    How to add all checkBoxes to a single list ? You can just hardcode 64 inserts in constructor, or if you have properly named the checkboxes in designer (like "checkBox_0", "checkBox_1", etc.) you can use QWidget::findChildren(const QString& name) method. Remeber that the order is important, so you probably can't simply call "findChildren" with an empty "name".
    What to do on each checkBox change ? Kind of inverse of the procedure described above, I think you will figure this out yourself.

  3. The following user says thank you to stampede for this useful post:

    Ryan111 (2nd April 2015)

  4. #3
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to write a program to show 64bit hex with checkbox?

    Yes, QLineEdit::textChanged() works, but it will be emitted repeatedly during edition, which may be a little too often. QLineEdit::editingFinished() is only emitted once edition is over. Pick your favorite, or experiment with them both.

    You may want to set an input mask on the QLineEdit (see QLineEdit::setInputMask()) to force the input to match a 16-digit hexadecimal number.

    Now, about the checkboxes. QCheckBox has a signal that is emitted whenever the state of the checkbox changes. Look up the fine documentation for details.

    Be careful about naive implementations: if you choose to react to QLineEdit::textChanged(), then every keystroke will cause the signal to be emitted, then your code will update the checkboxes, whose state will change, and your code may reset the QLineEdit's text once for each updated checkbox. I wonder how that may interfere with the user's editing.

  5. The following user says thank you to yeye_olive for this useful post:

    Ryan111 (2nd April 2015)

  6. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to write a program to show 64bit hex with checkbox?

    Be careful about naive implementations: if you choose to react to QLineEdit::textChanged(), then every keystroke will cause the signal to be emitted, then your code will update the checkboxes, whose state will change, and your code may reset the QLineEdit's text once for each updated checkbox
    Too bad you warned him, I really wanted Ryan to figure this out himself when trying to debug these lovely infinite loops

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to write a program to show 64bit hex with checkbox?

    SIde note: Your GUI doesn't have a layout applied.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #6
    Join Date
    Mar 2015
    Posts
    24
    Thanks
    20
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: How to write a program to show 64bit hex with checkbox?

    Quote Originally Posted by stampede View Post
    Too bad you warned him, I really wanted Ryan to figure this out himself when trying to debug these lovely infinite loops
    SomeOne is trying to make trouble for me!
    I'm a simple and poor 24 years old agricultural engineer from a small town(in Iran) then please make simple all things for me.
    Quote Originally Posted by wysota View Post
    SIde note: Your GUI doesn't have a layout applied.
    Is it necessary? or I can ignore it.

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to write a program to show 64bit hex with checkbox?

    Quote Originally Posted by Ryan111 View Post
    Is it necessary? or I can ignore it.
    If you want your program to behave correctly then it is necessary.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #8
    Join Date
    Mar 2015
    Posts
    24
    Thanks
    20
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: How to write a program to show 64bit hex with checkbox?

    Quote Originally Posted by wysota View Post
    If you want your program to behave correctly then it is necessary.
    certainly I do want. please define "behave". behave in shape and form and or it can make a bug in codes?

  11. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to write a program to show 64bit hex with checkbox?

    Shape and form E.g. if you want the window to resize properly or adjust to different font sizes people may have set in their systems.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. The following user says thank you to wysota for this useful post:

    Ryan111 (3rd April 2015)

  13. #10
    Join Date
    Mar 2015
    Posts
    24
    Thanks
    20
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: How to write a program to show 64bit hex with checkbox?

    Quote Originally Posted by wysota View Post
    Shape and form E.g. if you want the window to resize properly or adjust to different font sizes people may have set in their systems.
    Thanks buddy,
    I saw this clip:

    www.youtube.com/watch?v=PQEBoftbtVQ

Similar Threads

  1. recompile the program in a 64bit machine
    By saman_artorious in forum Qt Programming
    Replies: 1
    Last Post: 12th February 2014, 15:23
  2. Qt 32bit working on one 64bit PC and not on anoher 64bit PC
    By Matthiasabt in forum Qt Programming
    Replies: 0
    Last Post: 29th October 2013, 07:10
  3. Building 64bit Shared Qt Dlls on 64bit Win7 for Visual Studio
    By HarrySatt in forum Installation and Deployment
    Replies: 1
    Last Post: 29th November 2011, 04:39
  4. How to write a logging program for a web server
    By Niels Holst in forum Qt Programming
    Replies: 1
    Last Post: 23rd March 2011, 09:02
  5. Replies: 2
    Last Post: 2nd November 2010, 05:15

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.