December 25, 2010

lepepper lepepper
Lab Rat
5 posts

qt custom widgets propertis are not getting updated properly in Qt designer

 

I have created a custom widget.
The widget gets loaded fine,the properties appear in QT Designer,
Only problem is every time I change the property of Alpha key,the
numeric also gets set,
Though the accessor functions are different,and the enums are differnet
and values are different.
Also whenever i check the Form->view code,the values would have got
modified. Am i Missing something or this is a designer issue,Any workarounds
would be appreciated

  1. class key
  2. {
  3. Q_PROPERTY(AlphKeycode_t AlphKeycode READ AlphKeycode WRITE
  4. setAlphKeycode);
  5. Q_PROPERTY(bool AlphKey READ isAlph WRITE setAlph);
  6. Q_ENUMS(AlphKeycode_t);
  7.  
  8.  
  9. Q_PROPERTY(NumKeycode_t NumKeycode READ NumeKeycode WRITE
  10. setNumKeycode);
  11. Q_PROPERTY(bool NumKey READ isNum WRITE setNum);
  12. Q_ENUMS(NumKeycode_t);
  13.  
  14. private:
  15.   AlphKeycode_t   m_AlphaKeycode;
  16.   NumKeycode_t m_NumKeycode
  17.  
  18. }
  19. key::key(QWidget *parent) :
  20.     QPushButton(parent),
  21.    
  22.    m_AlphaKeycode(e_Keycode_Q),
  23.    m_NumKeycode(e_Keycode_1),
  24.    AlphaKey(false),
  25. NumericKey(false)
  26.  
  27. {
  28.      connect(this, SIGNAL(clicked()), this, SLOT(KeyClicked()));
  29. }
  30.  
  31. struct AlphData
  32. {
  33.   QString       label;
  34.     bool    isAlphabetic;
  35. };
  36.  
  37. struct NumData
  38. {
  39.     QString     label;
  40.     bool    isNumeric;
  41. };
  42.  
  43. AlphData AlphKeyData[] =
  44. {                                                                
  45.   {"q",true },
  46. }
  47. NumData NumKeyData[] =
  48. {
  49.   {"1", false},
  50. }
  51.  
  52. bool key::isAlphabetic()
  53. {
  54.     return AlphKeyData[m_AlphabeticKeycode].isAlphabetic;
  55. }
  56. void key::setAlphabetic(bool arg)
  57. {
  58.      AlphKeyData[m_AlphaKeycode].isAlphabetic = arg;
  59. }
  60.  
  61.  
  62. bool key::isNumeric()
  63. {
  64.      return NumKeyData[m_NumKeycode].isNumeric;
  65. }
  66.  
  67. void key::setNumeric(bool arg)
  68. {
  69.      NumKeyData[m_NumKeycode].isNumeric = arg;
  70. }
  71.  
  72.  
  73. //Slot Function
  74. void key::KeyClicked()
  75. {
  76.     if (AlphKeyData[m_AlphaKeycode].isAlphabetic)
  77.     {
  78.         Q_EMIT this->OnDataKeyClicked(m_AlphaKeycode);
  79.     }
  80.     if (NumKeyData[m_NumKeycode].isNumeric)
  81.     {
  82.         Q_EMIT this->OnDataKeyClicked(m_NumKeycode);
  83.     }
  84. }

[EDIT: added @-tags for code formatting, Volker]

4 replies

December 25, 2010

Milot Shala Milot Shala
Lab Rat
371 posts

Please use proper code format. And which version of Qt Creator are you testing your properties, maybe can be a Creator bug

December 25, 2010

Volker Volker
Ant Farmer
5331 posts

Your code does not show the relevant methods for handling the properties’ getters and setters. It’s hard to know what’s going wrong there.

December 27, 2010

lepepper lepepper
Lab Rat
5 posts

Thanks for the replies,Sorry for code formatting.

I am using Qt designer 4.7 on linux,The plugin is built on linux using C++code,with the usual MOC’ing and It generates ui_key.h
What Iam feeling is every time i create a new instance,The property editor does not start with a fresh set of default values. Some how it retains some old values,
I want to get something like
AlphaKey isAlpha
NumKey is Numeric
These should be unigue for a key,which means if i choose alpha,and set is alpha ,it should retain this property.
On creating a new key ,the property sheet still imagines that i need to create a alpha key and shows the isAlpha enabled.
so when i choose numeric,it sets the key to be true for both alpha and numeric using qVariant.
,hence the slot function goes for a toss.

I have not used any qvariant in code.Iam not aware how to disable this qvariant.
Also I would like the AlphaKey and NumericKey to be exclusive. Which means,If I create a alphakey and set it to alpha,next time I want to create Numeric,The property sheet should start fresh with all default values,and on setting it as numeric,It should just set it as numeric. Any ideas will be very helpful

December 27, 2010

Volker Volker
Ant Farmer
5331 posts

AlphData AlphKeyData[] is a regular C/C++ array and thus 0-based. You cannot access it with the character stored in it. Depending on the compiler and other circumstances you will cause a crash of your program.

In

  1. AlphKeyData[m_AlphabeticKeycode]

you access the array at index 81 or 113 (‘Q’ or ‘q’).

Apart from that, I do not understand what you want to do.

 
  ‹‹ QMatrix4x4 and OpenGL      How to move an object in a specified path... ››

You must log in to post a reply. Not a member yet? Register here!