Results 1 to 14 of 14

Thread: Possible signal mapper problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 Re: Possible signal mapper problem

    Ok, here is COperationWindow.h:
    Qt Code:
    1. class COperationWIndow : public QWidget
    2. //class COperationWIndow : public QDockWidget
    3. {
    4. Q_OBJECT
    5.  
    6. public:
    7. COperationWIndow(QWidget* pParent);
    8. ~COperationWIndow();
    9. void playVerbalDescription(QString sSound);
    10. // method for getting merchandize description
    11. QString getMerchandizeDescription(qint16 iMerchandizeId);
    12.  
    13. // inline methods for getting pointers of private members
    14. inline QPointer<CLanguageSelectorWidget> languageSelectorWidget() { return m_pLanguageSelectorWidget; };
    15.  
    16. private:
    17. QPointer<CMerchandizeBrowser> m_pMerchandizeBrowser; // pointer to merchandize browse
    18. QPointer<QVBoxLayout> m_pVLayout; // pointer to vertical layout
    19. QPointer<QHBoxLayout> m_pHLayout; // pointer to horizotnal layout
    20. QPointer<QHBoxLayout> m_pMainLayout; // pointer to main layout
    21. QPointer<QVBoxLayout> m_pCartLayout; // pointer to vertial layout
    22. QPointer<QPushButton> m_pLeftButtonMerchandizeSelector; // pointer to left merhcandize selector
    23. QPointer<QPushButton> m_pButtonMerchandizeConfirmer; // pointer to merchandize confirmer
    24. QPointer<QPushButton> m_pRightButtonMerchandizeSelector; // pointer to right merhcandize selector
    25. QPalette m_cPalette; // palette for changing colors
    26. QFont m_cFont; // font variable for changing fonts
    27. qint16 m_iSelected; // selected merchandize
    28. QPointer<QTimer> m_pAdvertisementTimer; // timer for advertisement mode
    29. QStringList m_MerchandizeGroupsNames; // structure to store merchandize group names
    30. QPointer<QHBoxLayout> m_pMerchandizeSelectorButtonsLayout; // horiz. layout for merchandize selector buttons
    31. QList <QPushButton*> m_MerchandizeSelectorButtons; // merchandize selector buttons
    32. //QList <QPointer<QPushButton> > m_pMerchandizeSelectorButtons; // merchandize selector buttons
    33. QPointer <QSignalMapper> m_pMerchandizeSelectorButtonSignalMapper; // pointer to buttons signal mapper
    34. QPointer<QPushButton> m_pSoftwareInformationButton; // button for triggering software info
    35. QPointer<CDatabaseFoundation> m_pDatabaseConnection; // connecion to dabase
    36. QPointer<QTabWidget> m_pMerchandizeTabWidget; // ponter to merchandize shooping cart & information widoget
    37. QPointer<CShoppingCart> m_pShoppingCart; // pointer to shopping cart
    38. QPointer<CLanguageSelectorWidget> m_pLanguageSelectorWidget; // language selector widget
    39. QPointer<QPushButton> m_pLanguageSelectorButton; // language selector button
    40.  
    41. private slots:
    42. // slot for showing left merchandize
    43. void showLeftMerchandize();
    44. // slot for showing right merchandize
    45. void showRightMerchandize();
    46. // slot for choosing merchandize
    47. void chooseMerchandize();
    48. // slot for avertising
    49. void startAdvertising();
    50. // slot for showing software info
    51. //void showSoftwareInfo();
    52. // slot for showing language selector
    53. void showLanguageSelectorWidget();
    54.  
    55. /* !
    56.   * slot for filtering merchandize pictures
    57.   */
    58. void filterMerchandize(int iMerchandizeGroup);
    59.  
    60. private:
    61. /* !
    62.   * creates tab widget
    63.   */
    64. void createShoppingCartWidget(QTabWidget* pParent);
    65. /* !
    66.   * creates Merchandize Information Widget
    67.   */
    68. void createMerchandizeInformationWidget(QTabWidget* pParent);
    69. /*!
    70.   * language change event filter
    71.   */
    72. void changeEvent(QEvent* e);
    73.  
    74.  
    75. signals:
    76. void clicked(const int &iIndex); // pushbutton slot
    77. };
    78.  
    79. #endif /*COPERATIONWINDOW_H_*/
    To copy to clipboard, switch view to plain text mode 
    As you can see, here is defined pointer to CLanguageSelectorWidget:
    Qt Code:
    1. QPointer<CLanguageSelectorWidget> m_pLanguageSelectorWidget; // language selector widget
    To copy to clipboard, switch view to plain text mode 
    and here is CLanguageSelectorWidget header:
    Qt Code:
    1. #define CLANGUAGESELECTORWIDGET_H_
    2.  
    3. /*!
    4.  * \class CLanguageSelectorWidget
    5.  * \author VSistemi Marko Frelih s.p.
    6.  * \version 1.0
    7.  * \date January 2007
    8.  * \brief This Qt based class represents a language selector widget, which constist of number of
    9.  * CFlagButton objects.
    10.  * \details version 1.00 (revision 84): basic functionality
    11. */
    12.  
    13. // qt includes
    14. #include <QDialog>
    15. #include <QHBoxLayout>
    16. #include <QVBoxLayout>
    17. #include <QList>
    18. #include <QFont>
    19. #include <QPalette>
    20. #include <QApplication>
    21. #include <QButtonGroup>
    22. #include <QSqlQuery>
    23. #include <QString>
    24. #include <QVector>
    25.  
    26. class QWidget; // forward declaration
    27.  
    28. // custom includes
    29. #include "CFlagButton.h"
    30. #include "cdatabasefoundation.h"
    31.  
    32. /*!
    33.  * class which contains flag buttons
    34.  */
    35. class CLanguageSelectorWidget : public QDialog
    36. {
    37. Q_OBJECT
    38.  
    39. public:
    40. CLanguageSelectorWidget(QWidget* pParent);
    41. ~CLanguageSelectorWidget();
    42. inline QPointer<QHBoxLayout> langaugeButtonsLayout() { return m_pLanguageButtonsLayout; };
    43. inline QPointer<QVBoxLayout> mainLayout() { return m_pMainLayout; };
    44. //inline QList<CFlagButton> languageButtonsList() { return mLanguageButtonsList; };
    45. inline QPalette widgetPalette() { return m_WidgetPalette; };
    46. /*
    47.   inline QPointer<CFlagButton> sloLangButton() { return m_pSloLangButton; };
    48.   inline QPointer<CFlagButton> ukLangButton() { return m_pUKLangButton; };
    49.   inline QPointer<CFlagButton> deuLangButton() { return m_pDeuLangButton; };
    50.   inline QPointer<CFlagButton> itaLangButton() { return m_pItaLangButton; };
    51. */
    52. inline qint16 numberOfLanguages() { return m_iNumberOfLanguages; };
    53. //inline void setNrOfLanguages(qint16 iNumber) { m_iNumberOfLanguages=iNumber; };
    54. inline void selectLanguage(qint16 iSelectedLanguage) { m_iSelectedLanguage=iSelectedLanguage; };
    55. inline qint16 selectedLanguage() { return m_iSelectedLanguage; };
    56.  
    57. private:
    58. QPointer<QHBoxLayout> m_pLanguageButtonsLayout; // horizontal layout
    59. QPointer<QVBoxLayout> m_pMainLayout; // main layouts
    60. QPalette m_WidgetPalette; // widget palette
    61. QList<QPointer<CFlagButton> > m_LangButtonGroup; // language button group
    62. QPointer<CDatabaseFoundation> m_pDatabaseConnection; // connecion to dabase
    63. qint16 m_iSelectedLanguage; // index of selected langauge
    64. // TODO: automatic hbox creation at higer number of language buttons
    65. QVector<QPointer<QHBoxLayout> > m_LangaugeButtonsLayout; // list of horizontal layers
    66. qint16 m_iNumberOfLanguages; // number of languages
    67.  
    68. private:
    69. // method for reading database and filling list with lang buttons
    70. QList<QPointer<CFlagButton> > createLangButtons();
    71.  
    72. private slots:
    73. void translate(const int iLanguageIdentificator);
    74. };
    75.  
    76. #endif /*CLANGUAGESELECTORWIDGET_H_*/
    To copy to clipboard, switch view to plain text mode 
    As we can see, here is a QList of CFlagButtons:
    Qt Code:
    1. QList<QPointer<CFlagButton> > m_LangButtonGroup; // language button group
    To copy to clipboard, switch view to plain text mode 
    Here I create object CLanguageSelectorWidget (in COperationWindow constructor):
    Qt Code:
    1. m_pLanguageSelectorButton=new QPushButton(QPixmap(":/flags/flagLanguageSelector"),
    2. QString(""),
    3. this); // creates lang. selector button
    4. Q_CHECK_PTR(m_pLanguageSelectorButton); // checks creation
    5. m_cPalette=m_pLanguageSelectorButton->palette(); // reads current palette
    6. m_cPalette.setColor(QPalette::Button, Qt::black); // sets up new palette componenet
    7. m_pLanguageSelectorButton->setPalette(m_cPalette); // sets new pallete
    8. m_pLanguageSelectorButton->setIconSize(QSize(128, 128)); // sets icon size
    9. // sets mask for reshaping button
    10. //m_pLanguageSelectorButton->setMask(QPixmap(":/flags/flagLanguageSelector").createHeuristicMask());
    11. connect(m_pLanguageSelectorButton, SIGNAL(clicked()),
    12. this, SLOT(showLanguageSelectorWidget())); // connects click to slot
    To copy to clipboard, switch view to plain text mode 
    And here is contructor of CLanguageSelectorWidget:
    Qt Code:
    1. CLanguageSelectorWidget::CLanguageSelectorWidget(QWidget* pParent) : QDialog(pParent)
    2. {
    3. // opens database connection
    4. m_pDatabaseConnection=CDatabaseFoundation::getInstance(strdbType, strdbHost, strDatabaseName, strdbUserName, strdbPassword);
    5. Q_CHECK_PTR(m_pDatabaseConnection); // checks creation
    6. // **** end of DATABASE CONNECTION
    7.  
    8. // sets up horiz layout vector
    9. m_LangaugeButtonsLayout.resize(iNumberOfButtons-1); // resizes layout pointer vector
    10. // **** end of setup horiz layout vector
    11. m_LangButtonGroup=createLangButtons(); // creates language buttons from database
    12. m_pLanguageButtonsLayout=new QHBoxLayout(); // creates new horiz layout
    13. Q_CHECK_PTR(m_pLanguageButtonsLayout); // checks creation
    14. for(int iIndex=0; iIndex<m_LangButtonGroup.size(); iIndex++)
    15. m_pLanguageButtonsLayout->addWidget(m_LangButtonGroup.at(iIndex));
    16. setWindowModality(Qt::WindowModal); // sets modal flag
    17.  
    18. // sets window palette
    19. setAutoFillBackground(true); // sets background auto fill ON
    20. m_WidgetPalette=this->palette(); // reads current palette
    21. m_WidgetPalette.setColor(QPalette::Background, Qt::black); // sets background color of widget
    22. setPalette(m_WidgetPalette); // installs modified palette
    23.  
    24. // sets window flags
    25. Qt::WindowFlags flags=Qt::FramelessWindowHint | Qt::Dialog; // sets window flags
    26. setWindowFlags(flags); // sets window flags
    27.  
    28. m_pMainLayout=new QVBoxLayout(); // creates main layout
    29. Q_CHECK_PTR(m_pMainLayout); // checks creation
    30. m_pMainLayout->addLayout(m_pLanguageButtonsLayout); // adds layout
    31. setLayout(m_pMainLayout); // sets new layout
    32. }
    To copy to clipboard, switch view to plain text mode 
    Do you need anything else?
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Possible signal mapper problem

    Ok, but I asked for the relevant code, not the whole code Could you suggest which part is relevant to the problem?

    Qt Code:
    1. inline QPointer<QHBoxLayout> langaugeButtonsLayout() { return m_pLanguageButtonsLayout; };
    To copy to clipboard, switch view to plain text mode 
    What is this? Why do you return a QPointer to a layout?

    Why does translate() take const int and not just int?

    QVector and QList of QPointers? Why?

  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: Possible signal mapper problem

    It is not a whole code, just classes relevenat to problem. Well, as you can see, the problem is when I try to find out which language is selected in COperationWindow object, I get weird values. The signal mapper communication between CFlagButton and CLanguageSelectorWodget works ok, I've checked it with gdb. Why does method
    Qt Code:
    1. selectedLanguage()
    To copy to clipboard, switch view to plain text mode 
    from
    Qt Code:
    1. QPointer<CLanguageSelectorWidget> m_pLanguageSelectorWidget;
    To copy to clipboard, switch view to plain text mode 
    returns weird results?? This is my question excatly. Other your remarks regarding code will be fixed in future.
    Qt 5.3 Opensource & Creator 3.1.2

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

    Default Re: Possible signal mapper problem

    Where do you call selectLanguage()?

    m_iSelectedLanguage is not initialized in the constructor and selectLanguage() is the only method that changes its value. If you don't call it, it will contain a random number, possibly the one you are receiving...

    And by the way - where is the signal mapper in all that?

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

    MarkoSan (25th January 2008)

  6. #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

    Thumbs up Re: Possible signal mapper problem

    God damn, wysota, thank you very very much, If you ever come to Slovenia (with jpn), contact me, I owe you and a jpn a lot of beers!!!!!!!! IT WORKS NOW!!!!!
    Qt 5.3 Opensource & Creator 3.1.2

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

    Default Re: Possible signal mapper problem

    What if I come without jpn?

  8. #7
    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: Possible signal mapper problem

    you're welcome, it is urgent to drink some beers.
    Qt 5.3 Opensource & Creator 3.1.2

  9. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Possible signal mapper problem

    Quote Originally Posted by MarkoSan View Post
    If you ever come to Slovenia (with jpn), contact me, I owe you and a jpn a lot of beers!!!!!!!!
    Thanks for the invitation.

    Quote Originally Posted by wysota View Post
    What if I come without jpn?
    Does that mean you'd rather go without me?
    J-P Nurmi

  10. #9
    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: Possible signal mapper problem

    I do not know what relation are you two in, but I invited both. I reserve 60 beers per developer per weekend, is this enough?
    Qt 5.3 Opensource & Creator 3.1.2

Similar Threads

  1. QLineEdit - lostFocus signal problem
    By Enygma in forum Qt Programming
    Replies: 6
    Last Post: 17th June 2010, 21:52
  2. QListWidget SIGNAL Problem
    By skuda in forum Qt Programming
    Replies: 19
    Last Post: 28th October 2009, 15:42
  3. Problem emitting signal from a static function
    By Valheru in forum Qt Programming
    Replies: 21
    Last Post: 12th June 2007, 15:48
  4. Replies: 3
    Last Post: 15th April 2007, 20:16
  5. Signal problem in Qline Edit
    By awalesminfo in forum Newbie
    Replies: 1
    Last Post: 3rd April 2006, 10:13

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.