Qt World Summit: Register Today!

IP Address Editor with popup numberpad

  • I am creating an IP Editor widget by using 4 LineEdits. When you click on a LineEdit, a numberpad pops up for touch interfaces. My question is, how can I make the code general? For example, for single LineEdits, I can have a SIGNAL/SLOT

    connect(lineedit, SIGNAL(sendData(QString), this, SLOT(receiveData(QString));

    and then in my receiveData function it'd look something like:

    void IPEditor::receiveData(const QString &text)
       QLineEdit *mask = qobject_cast<QLineEdit*>(sender());

    How would I go about doing so with 4 LineEdits?

    PS - I will also be accepting keyboard inputs, but I figure I'll figure that part out once I get the touchpad working. Thanks!

  • @Sh1gs

    I think you should have a look to QSignalMapper

    However, I am wondering why you are going for four lineedits? A lineedit per three digit part of an ipv4 address?
    If that is your idea, you could do also with an input mask.

  • @koahnig

    I will have to research QSignalMapper to see if that will work for my purpose. I am creating a custom IP Editor plugin for a project at work, which needs to let the user define each input mask individually, hence the 4 lineedits. The input mask doesn't work because of the popup numberpad. I will look into SignalMapper and report back. If anyone else has suggestions, it would be much appreciated.

  • @koahnig

    I'm still confused about QSignalMapper. I've searched, and it looks like it'd benefit me on the touchscreen numberpad portion, but am unsure how to go about it with the 4 lineedits. There is this example: http://stackoverflow.com/questions/9306335/an-ip-address-widget-for-qt-similar-to-mfcs-ip-address-control. The top voted answer would be perfect if I was just accepting keyboard inputs, but since I'm also doing a touchscreen numberpad, I'm confused as to how to correctly implement it. Does that make sense?

  • @Sh1gs

    I do not understand why you actually require 4 lineedits for one IP address input. The natural assumption is that you are trying to retrieve each field individually. The more natural, but also more complicated way in view of a perfect solution, seems a solution with one lineedit and an input mask.

    There is somewhere in the forum a thread, which presumably I have even started, but can't find anymore. It is a couple of years old and was probably taken over into the new system.
    Anyway there has been a response with an QRegExp validator expression. It works reasonably well, but has some visible flaws. IMHO it would be a better start, but your apporach may be more elegant after you have negotiated around your issues.

    Concerning touchscreen keyboard w/o physical keyboard, I have no experience at all and therefore, I have to bail out.

  • I am going to mark this topic as Solved. I used a lot of the methodologies from this topic. I used 4 lineedits because I'm building a plugin and I want the user to be able to enter each input mask individually.