Good morning, sehr geheerte Damen und Herren! ![Big Grin](images/smilies/biggrin.png)
I have problem I cannot crack. I have three classes, that need to cooperate. Namely, I am writing language change aware app and I coded a class, derived from QPushButton, which represent a "nation flag button". It is subclassed from QPushButton and also it holds a private member:
private:
qint16 m_iLanguageId; // language id number
private:
qint16 m_iLanguageId; // language id number
To copy to clipboard, switch view to plain text mode
which is id number from database. When creating an object from CFlagButton, this number is set correctly. But I simply cannot send this number via signal mapper i wrote to its parent window, CLanguageSelectorWidget, which holds more of CFlagButtons (for every langauge in database there is appropriate flag button). Here is signal mapper I wrote:
CFlagButton
::CFlagButton(QWidget* pParent,
bool captionShown,
const qint16 iLanguageIdentificator)
{
....
m_pFlagButtonSM=new QSignalMapper(this);
// creates new signal mapper Q_CHECK_PTR(m_pFlagButtonSM); // checks creation
// installation of translator
m_pTranslator
=new QTranslator(qApp);
// creats new translator Q_CHECK_PTR(m_pTranslator); // checks creation
m_pTranslator->load(langTranslator); // loads translator
connect(this,
SIGNAL(clicked()),
m_pFlagButtonSM,
SLOT(map())); // connects button to signal mapper
m_pFlagButtonSM->setMapping(this, (int)m_iLanguageId); // sets mapping
/*
connect(m_pFlagButtonSM,
SIGNAL(mapped(int)),
this,
SIGNAL(clicked(const int))); // connects signal mapper to button
connect(this, SIGNAL(clicked(const int)),
pParent, SLOT(translate(const int))); // connects emited signal to slot
*/
connect(m_pFlagButtonSM,
SIGNAL(mapped(int)),
pParent,
SLOT(translate(const int))); // connects signal mapper to translator
....
}
CFlagButton::CFlagButton(QWidget* pParent,
const QString flagPicture,
const QString flagCaption,
bool captionShown,
const QString langTranslator,
const qint16 iLanguageIdentificator)
{
....
m_pFlagButtonSM=new QSignalMapper(this); // creates new signal mapper
Q_CHECK_PTR(m_pFlagButtonSM); // checks creation
// installation of translator
m_pTranslator=new QTranslator(qApp); // creats new translator
Q_CHECK_PTR(m_pTranslator); // checks creation
m_pTranslator->load(langTranslator); // loads translator
connect(this,
SIGNAL(clicked()),
m_pFlagButtonSM,
SLOT(map())); // connects button to signal mapper
m_pFlagButtonSM->setMapping(this, (int)m_iLanguageId); // sets mapping
/*
connect(m_pFlagButtonSM,
SIGNAL(mapped(int)),
this,
SIGNAL(clicked(const int))); // connects signal mapper to button
connect(this, SIGNAL(clicked(const int)),
pParent, SLOT(translate(const int))); // connects emited signal to slot
*/
connect(m_pFlagButtonSM,
SIGNAL(mapped(int)),
pParent,
SLOT(translate(const int))); // connects signal mapper to translator
....
}
To copy to clipboard, switch view to plain text mode
pParent here is CLanguageSelectorWidget object and its translate() slot is:
void CLanguageSelectorWidget::translate(const int iLanguageIdentificator)
{
qDebug() << "iLanguageIdentificator: " << iLanguageIdentificator;
qApp->installTranslator(m_LangButtonGroup.at(iLanguageIdentificator-1)->translator()); // installs translator
accept(); // closes parent window
}
void CLanguageSelectorWidget::translate(const int iLanguageIdentificator)
{
qDebug() << "iLanguageIdentificator: " << iLanguageIdentificator;
qApp->installTranslator(m_LangButtonGroup.at(iLanguageIdentificator-1)->translator()); // installs translator
accept(); // closes parent window
}
To copy to clipboard, switch view to plain text mode
m_LangButton group is defined as:
QList<QPointer<CFlagButton> > m_LangButtonGroup; // language button group
QList<QPointer<CFlagButton> > m_LangButtonGroup; // language button group
To copy to clipboard, switch view to plain text mode
I've entered into debugger, set the breakpoints and the cruical member variable m_iLanguageId holds -4096 or -4098 values (it seems it is not initialized properly)
In constructor of CFlagButton the variable is initalized properly - checked with gdb.
Can nice jpn or other nice experts help me?
Bookmarks