Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, March 2008
Instant apply windows


Message 1 in thread

Hi list,

Is there a way to implement instant apply windows[*] in Qt?
My configuration window has several linedits, I tried to play with
editingFinished() signal, but without any success.

The problem is that editingFinished() doesn't receive the current
contents of a lineedit. Here is a snippet from my code:

    QList<QLineEdit*> leList;
    leList << lineEdit_1
           << lineEdit_2
           << lineEdit_3
           << lineEdit_4;

    QList<QString> values;
    values << lineEdit_1->text()
           << lineEdit_2->text()
           << lineEdit_3->text()
           << lineEdit_4->text();
    
    signalMapper = new QSignalMapper(this);
    for (int i = 0; i < 4; i++)
    {
        connect(leList[i], SIGNAL(editingFinished()), signalMapper,
SLOT(map()));
        signalMapper->setMapping(leList[i], values[i]);            
    }

    connect(signalMapper, SIGNAL(mapped(QString)),
             this, SIGNAL(editingFinished(QString)));

    connect(this, SIGNAL(editingFinished(QString)),
                 this, SLOT(writeSettings(QString)));

I believe something is wrong with mapping to ïtext() properties of a
lineedit, but what is the right way of doing this?

The other drawback of this method is that I can't get the
sender(lineedit) of a signal in my ïwriteSettings slot. How to overcome
this?

Thanks for any feedback.


[*]
http://library.gnome.org/devel/hig-book/stable/windows-utility.html.en#windows-instant-apply

-- 
 [ signature omitted ] 

Message 2 in thread

On sÃndag den 2. Marts 2008, Nikolay Derkach wrote:
> Is there a way to implement instant apply windows[*] in Qt?

Of course. You just need to figure out how.

You should not use a signal mapper for this problem. Instead, do this:

foreach(QLineEdit* le, leList)
  connect(le, SIGNAL(editingFinished(const QString&)),
          this, SLOT(writeSettings(const QString&)));

In your writeSettings slot, you can call sender() and find out which of the 
line edits have changed the text.

A QSignalMapper object is good when you want to parameterize a set of widgets. 
For example, you have 10 buttons, and you want to have a single slot that 
just takes an int as argument, and this int tells which of the buttons was 
pressed.

I hope this helps.

Bo.

> My configuration window has several linedits, I tried to play with
> editingFinished() signal, but without any success.
>
> The problem is that editingFinished() doesn't receive the current
> contents of a lineedit. Here is a snippet from my code:
>
>     QList<QLineEdit*> leList;
>     leList << lineEdit_1
>            << lineEdit_2
>            << lineEdit_3
>            << lineEdit_4;
>
>     QList<QString> values;
>     values << lineEdit_1->text()
>            << lineEdit_2->text()
>            << lineEdit_3->text()
>            << lineEdit_4->text();
>
>     signalMapper = new QSignalMapper(this);
>     for (int i = 0; i < 4; i++)
>     {
>         connect(leList[i], SIGNAL(editingFinished()), signalMapper,
> SLOT(map()));
>         signalMapper->setMapping(leList[i], values[i]);
>     }
>
>     connect(signalMapper, SIGNAL(mapped(QString)),
>              this, SIGNAL(editingFinished(QString)));
>
>     connect(this, SIGNAL(editingFinished(QString)),
>                  this, SLOT(writeSettings(QString)));
>
> I believe something is wrong with mapping to ïtext() properties of a
> lineedit, but what is the right way of doing this?
>
> The other drawback of this method is that I can't get the
> sender(lineedit) of a signal in my ïwriteSettings slot. How to overcome
> this?
>
> Thanks for any feedback.
>
>
> [*]
> http://library.gnome.org/devel/hig-book/stable/windows-utility.html.en#wind
>ows-instant-apply



-- 
 [ signature omitted ] 

Message 3 in thread

Hi Bo,

Thanks for your reply.

2008/3/3, Bo Thorsen <bo@xxxxxxxxxxxxxxxxxxxxx>:
>
> On søndag den 2. Marts 2008, Nikolay Derkach wrote:
> > Is there a way to implement instant apply windows[*] in Qt?
>
>
> Of course. You just need to figure out how.
>
> You should not use a signal mapper for this problem. Instead, do this:
>
> foreach(QLineEdit* le, leList)
>   connect(le, SIGNAL(editingFinished(const QString&)),
>           this, SLOT(writeSettings(const QString&)));


The problem is that editingFinished() method has no parameters. That's why I
had tried using QSignalMapper to add a QString option. Is there any simple
way to overload editingFinished()?

In your writeSettings slot, you can call sender() and find out which of the
> line edits have changed the text.
>
> A QSignalMapper object is good when you want to parameterize a set of
> widgets.
> For example, you have 10 buttons, and you want to have a single slot that
> just takes an int as argument, and this int tells which of the buttons was
> pressed.


I believe this is exactly my case. Probably I misunderstand something?


-- 
 [ signature omitted ] 

Message 4 in thread

On mandag den 3. Marts 2008, Nikolay Derkach wrote:
> Hi Bo,
>
> Thanks for your reply.
>
> 2008/3/3, Bo Thorsen <bo@xxxxxxxxxxxxxxxxxxxxx>:
> > On søndag den 2. Marts 2008, Nikolay Derkach wrote:
> > > Is there a way to implement instant apply windows[*] in Qt?
> >
> > Of course. You just need to figure out how.
> >
> > You should not use a signal mapper for this problem. Instead, do this:
> >
> > foreach(QLineEdit* le, leList)
> >   connect(le, SIGNAL(editingFinished(const QString&)),
> >           this, SLOT(writeSettings(const QString&)));
>
> The problem is that editingFinished() method has no parameters. That's why
> I had tried using QSignalMapper to add a QString option. Is there any
> simple way to overload editingFinished()?

No. When I wrote it, I assumed you had this one set.

Instead, do this:

QLineEdit* lineEdit = qobject_cast<QLineEdit*>(sender());
QString text = lineEdit->text();

Bo.

> In your writeSettings slot, you can call sender() and find out which of the
>
> > line edits have changed the text.
> >
> > A QSignalMapper object is good when you want to parameterize a set of
> > widgets.
> > For example, you have 10 buttons, and you want to have a single slot that
> > just takes an int as argument, and this int tells which of the buttons
> > was pressed.
>
> I believe this is exactly my case. Probably I misunderstand something?



-- 
 [ signature omitted ] 

Message 5 in thread

2008/3/3, Bo Thorsen <bo@xxxxxxxxxxxxxxxxxxxxx>:
>
> On mandag den 3. Marts 2008, Nikolay Derkach wrote:
> > Hi Bo,
> >
> > Thanks for your reply.
> >
> > 2008/3/3, Bo Thorsen <bo@xxxxxxxxxxxxxxxxxxxxx>:
> > > On søndag den 2. Marts 2008, Nikolay Derkach wrote:
> > > > Is there a way to implement instant apply windows[*] in Qt?
> > >
> > > Of course. You just need to figure out how.
> > >
> > > You should not use a signal mapper for this problem. Instead, do this:
> > >
> > > foreach(QLineEdit* le, leList)
> > >   connect(le, SIGNAL(editingFinished(const QString&)),
> > >           this, SLOT(writeSettings(const QString&)));
> >
> > The problem is that editingFinished() method has no parameters. That's
> why
> > I had tried using QSignalMapper to add a QString option. Is there any
> > simple way to overload editingFinished()?
>
>
> No. When I wrote it, I assumed you had this one set.
>
> Instead, do this:
>
> QLineEdit* lineEdit = qobject_cast<QLineEdit*>(sender());
> QString text = lineEdit->text();
>
>
> Bo.


Thanks again. Works like a charm!


-- 
 [ signature omitted ]