PDA

View Full Version : How to enabled button, when i changed lineedit`s text ?



newermind
13th August 2009, 07:52
First, My save button is disabled. And I have 10 qlineedits.

I try to enabled button, when i changed a lineedit`s text.

I did this;

connect( m_ui->line_edit_1, SIGNAL( textChanged(const QString &) ), this, SLOT( BUTON_IS_ENABLED ( ) ) );

Do I write this code, all lineedits connect ?

Can i do this, if change something in dialog, button is enabled ?

yogeshgokul
13th August 2009, 07:56
connect( m_ui->line_edit_1, SIGNAL( textChanged(const QString &) ), this, SLOT( BUTON_IS_ENABLED ( ) ) );

What is
BUTON_IS_ENABLED
Is this a slot of what?

newermind
13th August 2009, 08:05
BUTON_IS_ENABLED is my function.


BUTON_IS_ENABLED ( )
{
m_ui->save_button->setEnabled(true);
}

wagmare
13th August 2009, 08:08
BUTON_IS_ENABLED ( )
this should be a private slot like
void make_button_enable();

inside make_button_enable()
set button->setEnabled(true);


Do I write this code, all lineedits connect ?
yes u have to ... to truncate lines u can use QList<QLineEdit *> but it is very tedious for simple connect ()

newermind
13th August 2009, 08:16
In this dialog change anything, these are lineedits, textedits or combo box.

For i make button enabled, Do i have to control all widgets ?

yogeshgokul
13th August 2009, 08:19
In this dialog change anything, these are lineedits, textedits or combo box.
For i make button enabled, Do i have to control all widgets ?
It seems like, you want to enable buttons, for any keyboard event. So instead of controlling all widgets, use event filter. Look for QKeyEvent. In this event, enable all your buttons.

aamer4yu
13th August 2009, 08:43
Do I write this code, all lineedits connect ?
Yes.. connect( m_ui->line_edit_1, SIGNAL( textChanged(const QString &) ), this, SLOT( BUTON_IS_ENABLED ( ) ) ); is connectting only line_edit_1 to the slot..
U will need to connect all line edits to ur slot..

also make sure ur function is declared as a SLOT - private/public slots:

XpycT
13th August 2009, 08:54
Try this:
Change your slot from BUTON_IS_ENABLED ( ) to BUTON_IS_ENABLED ( const QString &text).
Then use

connect( m_ui->line_edit_1, SIGNAL( textChanged(const QString &) ), this, SLOT( BUTON_IS_ENABLED ( const QString &) ) );
and chane your slot to

BUTON_IS_ENABLED ( const QString &text )
{
m_ui->save_button->setEnabled(!text.isEmpty());
}

aamer4yu
13th August 2009, 08:57
That wont matter since you can have slot with less number of arguments than the signal !