Results 1 to 5 of 5

Thread: QtPieMenu problem

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Default QtPieMenu problem

    Hello, I've created pie menu using QtPieMenu. Data shown in pei menu is loaded from database dynamically and every button gets its id then (from database). Now, how do I check which button was pressed in piemenu, I need this data. Please help!
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: QtPieMenu problem

    What signals you get on clicked ?
    You can however always check the sender(), cast it to the known class, and use the id to recognise which button was clicked

  3. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Default Re: QtPieMenu problem

    From the pie menu docs, I saw there is activeted(int i) signal, but I cannot catch it, been trying for 2 days now:
    Qt Code:
    1. connect(this,
    2. SIGNAL(activated(int)),
    3. this,
    4. SLOT(languageChanged(int)));
    To copy to clipboard, switch view to plain text mode 
    simply does not work and I do not know why.
    Qt 5.3 Opensource & Creator 3.1.2

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: QtPieMenu problem

    How are you connecting the signal ? Can we see the code ?

  5. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Default Re: QtPieMenu problem

    Ok, here is header file:
    Qt Code:
    1. /*
    2.  * CLangSelectorMenu.h
    3.  *
    4.  * Created on: 21.5.2009
    5.  * Author: markofr
    6.  */
    7.  
    8. #ifndef CLANGSELECTORMENU_H_
    9. #define CLANGSELECTORMENU_H_
    10.  
    11. // qt includes
    12. #include <QtCore/QString>
    13. #include <QtGui/QWidget>
    14. #include <QtCore/QList>
    15. #include <QtSql/QSqlQuery>
    16. #include <QtGui/QIcon>
    17. #include <QtGui/QPixmap>
    18. #include <QtGui/QMessageBox> // debug purposes
    19.  
    20. // custom includes
    21. #include "src/qtpiemenu/qtpiemenu.h"
    22. #include "globals.h"
    23. #include "CDatabaseFoundation.h"
    24.  
    25. // database table declaration
    26. typedef struct
    27. {
    28. quint32 iLangId; // language id
    29. QString strName; // language name
    30. QString strTranslatorFilePath; // language translator file path
    31. QString strPicPath; // language picture path
    32. QString strCurrency; // language curreny abbervavtion
    33. } langStruct;
    34.  
    35. class CLangSelectorMenu : public QtPieMenu
    36. {
    37. Q_OBJECT
    38.  
    39. public:
    40. CLangSelectorMenu(const QString& strText,
    41. QWidget* pParent=0,
    42. const char* pName=0,
    43. quint16 iInnerRadius=60,
    44. quint16 iOuterRadius=200);
    45. ~CLangSelectorMenu();
    46.  
    47. inline QList<langStruct> languages() const
    48. { return m_listLanguages; };
    49. inline QSqlQuery* languageQuery() const
    50. { return m_pLanguageQuery; };
    51. inline CDatabaseFoundation* databaseConnector() const
    52. { return m_pDatabaseConnector; };
    53. inline quint32 currentLanguage() const
    54. { return m_iCurrentLanguage; };
    55. inline void setCurrentLanguage(const quint32& iNewLanguage)
    56. { m_iCurrentLanguage=iNewLanguage; };
    57.  
    58. private:
    59. QList<langStruct> m_listLanguages; // list of languages
    60. QSqlQuery* m_pLanguageQuery; // language sql query
    61. CDatabaseFoundation* m_pDatabaseConnector; // database connector
    62. quint32 m_iCurrentLanguage; // current language id
    63.  
    64. private:
    65. void fetchLanguages(); // gets languages from database
    66. void createLangQuery(); // creates query object
    67. void setupMenu(); // setups language menu according to database
    68. void showString(const QString& strToShow); // debug method
    69.  
    70. private slots:
    71. void ignoreAction();
    72. void languageChanged(int i);
    73.  
    74. signals:
    75. void activated(int i);
    76. };
    77.  
    78. #endif /* CLANGSELECTORMENU_H_ */
    To copy to clipboard, switch view to plain text mode 
    and here is its implementation:
    Qt Code:
    1. /*
    2.  * CLangSelectorMenu.cpp
    3.  *
    4.  * Created on: 21.5.2009
    5.  * Author: markofr
    6.  */
    7.  
    8. #include "CLangSelectorMenu.h"
    9.  
    10. CLangSelectorMenu::CLangSelectorMenu(const QString& strText,
    11. QWidget* pParent,
    12. const char* pName,
    13. quint16 iInnerRadius,
    14. quint16 iOuterRadius)
    15. : QtPieMenu(strText,
    16. pParent,
    17. pName,
    18. static_cast<uint>(iInnerRadius),
    19. static_cast<uint>(iOuterRadius))
    20. {
    21. m_pDatabaseConnector=CDatabaseFoundation::getInstance(strdbType, strdbHost, strDatabaseName, strdbUserName, strdbPassword);
    22. Q_CHECK_PTR(m_pDatabaseConnector); // checks creation
    23.  
    24. setCurrentLanguage(1); // test purposes
    25. createLangQuery(); // creates query object
    26. fetchLanguages(); // creates language list
    27. setupMenu(); // sets up menu
    28. connect(this,
    29. SIGNAL(activated(int)),
    30. this,
    31. SLOT(languageChanged(int)));
    32. }
    33.  
    34. CLangSelectorMenu::~CLangSelectorMenu()
    35. {
    36. }
    37.  
    38. void CLangSelectorMenu::fetchLanguages()
    39. {
    40. langStruct tempRecord;
    41.  
    42. languageQuery()->exec("SELECT * FROM erosystem.language WHERE InUse=TRUE;"); // executes mysql query
    43. if(languageQuery()->isActive())
    44. {
    45. // query active, no errors
    46. while(languageQuery()->next())
    47. {
    48. // fetch records
    49. tempRecord.iLangId=languageQuery()->value(iLanguageFieldID).toInt();
    50. tempRecord.strCurrency=languageQuery()->value(iLanguageFieldCurrency).toString();
    51. tempRecord.strName=languageQuery()->value(iLanguageFieldLName).toString();
    52. tempRecord.strPicPath=languageQuery()->value(iLanguageFieldFlagPath).toString();
    53. tempRecord.strTranslatorFilePath=languageQuery()->value(iLanguageFieldTranPath).toString();
    54. //languages().append(tempRecord); // adds record to list
    55. m_listLanguages.append(tempRecord); // adds record to list
    56. }
    57. }
    58. else
    59. {
    60. // query not active, error handler
    61. showString(tr("Query not active.")); // shows error
    62. }
    63. }
    64.  
    65. void CLangSelectorMenu::createLangQuery()
    66. {
    67. m_pLanguageQuery=new QSqlQuery(databaseConnector()->m_Database); // creates language query
    68. Q_CHECK_PTR(m_pLanguageQuery); // checks creation
    69. }
    70.  
    71. void CLangSelectorMenu::setupMenu()
    72. {
    73. //showString("m_listLanguages.size():"+QString::number(m_listLanguages.size())); // debug
    74. for(int iIndex=0; iIndex<m_listLanguages.size(); iIndex++)
    75. {
    76. //showString("Pic path:"+m_listLanguages.at(iIndex).strPicPath); // debug
    77. insertItem(QIcon(QPixmap(m_listLanguages.at(iIndex).strPicPath)),
    78. QString(m_listLanguages.at(iIndex).strName),
    79. this,
    80. SLOT(ignoreAction())); // inserts flag
    81. }
    82. }
    83.  
    84. void CLangSelectorMenu::ignoreAction()
    85. {
    86. showString("Language changed."); // debug
    87. }
    88.  
    89. void CLangSelectorMenu::showString(const QString& strToShow)
    90. {
    91. QMessageBox tempBox;
    92. tempBox.setText(strToShow);
    93. tempBox.exec();
    94. }
    95.  
    96. void CLangSelectorMenu::languageChanged(int i)
    97. {
    98. showString(QString::number(i)); // debug
    99. }
    To copy to clipboard, switch view to plain text mode 
    Qt 5.3 Opensource & Creator 3.1.2

Similar Threads

  1. Replies: 1
    Last Post: 23rd April 2009, 09:05
  2. Very strange socket programming problem
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2008, 12:05
  3. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  4. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.