Results 1 to 9 of 9

Thread: Hex viewer in qt?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Hex viewer in qt?

    you can make hexviewer by using text edit event filter. I am send you code of hex viewer from my project.
    Qt Code:
    1. bool ProgramMemoryWindow::eventFilter(QObject *target, QEvent *event)
    2. {
    3. if (target == m_pProgamWindow)
    4. {
    5. if (event->type() == QEvent::KeyPress)
    6. {
    7. QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
    8.  
    9. if ((keyEvent->key() == Qt::Key_unknown)||(keyEvent->key() == 0))
    10. {
    11. return true;
    12. }
    13.  
    14. QString str1 = keyEvent->text();
    15. if (str1)
    16. {
    17.  
    18. char ch = *(str1.ascii());
    19. bool res = true;
    20. if (((ch <= '9' && ch >= '0') | (ch <= 'F' && ch >= 'A') |
    21. (ch <= 'f' && ch >= 'a')))
    22. {
    23. int para,index;
    24. static char chcnt=0;
    25. chcnt++;
    26. m_pProgamWindow->getCursorPosition(&para,&index);
    27. if ((index % 3 == 0))
    28. {
    29. m_pProgamWindow->setCursorPosition(para,index+1);
    30. chcnt = 0;
    31. }
    32. if ((index == 54) && (para == 15))
    33. {
    34. return true;
    35. }
    36. m_pProgamWindow->getCursorPosition(&para,&index);
    37. char value;
    38. getAddressFromPosition(para,index,ch,&value);
    39. char str[4];
    40. if ((value<0x7f)&&(value>0x1F))
    41. str[0]= value;
    42. else
    43. str[0] = 0x2e;
    44. str[1]= '\0';
    45. unsigned int asciipos = ((index - 7)/3)+55;
    46. m_pProgamWindow->setSelection(para,asciipos,para,asciipos+1,0);
    47. m_pProgamWindow->removeSelectedText(0);
    48. m_pProgamWindow->setColor(QColor(255,0,0));
    49. m_pProgamWindow->insertAt(str,para,asciipos);
    50. m_pProgamWindow->selectAll(false);
    51. m_pProgamWindow->setCursorPosition(para,index);
    52. m_pProgamWindow->setSelection(para,index,para,index+1,0);
    53. m_pProgamWindow->setColor(QColor(255,0,0));
    54. return QWidget::eventFilter(target, event);
    55. }
    56. }
    57. if ((keyEvent->key() == Qt::Key_Left )||(keyEvent->key() == Qt::Key_Up )||
    58. (keyEvent->key()==Qt::Key_Right )||(keyEvent->key()==Qt::Key_Down ))
    59. {
    60. return QWidget::eventFilter(target, event);
    61. }
    62. if ((keyEvent->key()==Qt::Key_Enter)||(keyEvent->key()==Qt::Key_Return))
    63. {
    64. saveContents();
    65. return true;
    66. }
    67. if ((keyEvent->key()==Qt::Key_Escape))
    68. {
    69. revertData();
    70. return true;
    71. }
    72. if ((keyEvent->key()==Qt::Key_PageDown))
    73. {
    74. onDownScrollClicked();
    75. return true;
    76. }
    77. if ((keyEvent->key()==Qt::Key_PageUp))
    78. {
    79. onUpScrollClicked();
    80. return true;
    81. }
    82. return true;
    83. }
    84. if ((event->type()== QEvent::Wheel))
    85. {
    86. return true;
    87. }
    88. if(!((event->type()== 10)||(event->type()== 11)||(event->type()== 24)||(event->type()== 25)||(event->type()== 12)))
    89. return QWidget::eventFilter(target, event);
    90.  
    91. }
    92.  
    93. return QWidget::eventFilter(target, event);
    94.  
    95. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 16th July 2007 at 13:05. Reason: changed [html] to [code]

Similar Threads

  1. Requirement for versatile image viewer
    By deekayt in forum General Discussion
    Replies: 1
    Last Post: 27th October 2006, 14:28
  2. How can i build a source viewer for debugger
    By blobgrinder in forum Qt Programming
    Replies: 3
    Last Post: 24th October 2006, 11:50
  3. ".hlp" viewer
    By boss_bhat in forum Qt Programming
    Replies: 3
    Last Post: 6th June 2006, 14:44
  4. jpeg viewer
    By chap19150 in forum Qt Programming
    Replies: 9
    Last Post: 6th June 2006, 11:57
  5. Image Viewer
    By sumsin in forum Qt Programming
    Replies: 3
    Last Post: 14th March 2006, 13:29

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.