×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    192

    Question Re access a label after creating several one with the same name &different objectname

    Hi,

    I have a little problem with accessing a label, after creating several labels using the same name.
    Each time i create a label, i use the following code:
    Code:
    QLabel* lbl = new QLabel(" ", ui->scrollAreaContents);
    The problem is that I don't know how to re access a specified label in order to change the text of the corresponding label.
    I tried to set for each "lbl" created an ObjectName, in order to differentiate between all the labels created:
    Code:
    lbl->setObjectName("label" + QString::number(i));

    Is the setObjectName() a good way to solve my problem? if so, how should i change the text of a specified label using the ObjectName ?
    And if it's not a good solution, how should i solve my problem ?

    Any help would be appreciated,

    Best Regards,
    Lipos123

  2. #2
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    228

    Re: Re access a label after creating several one with the same name &different object

    why dont u use a list of label?!??
    try to use like this
    i use that for push button
    QList<QPushButton*> myPushButtonArray;

    for (int n = 1; n <=10; n++)
    {
    myPushButtonArray[n] = new QPushButton("whatever the name here",this);
    }
    and u can use sender() function to know which button is pressed for example
    as for ex:
    connect(myPushButtonArray.at(n), SIGNAL(clicked()),this, SLOT(test()));

    void MainWindow::test()
    {

    if(sender()== myPushButtonArray.at(1))
    {
    QMessageBox::information(this,"" , "button1");
    }

    }
    hope that will help you
    Rondo
    Last edited by Rondo23; 2011-09-21 at 07:45.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    192

    Re: Re access a label after creating several one with the same name &different object

    Quote Originally Posted by Rondo23 View Post
    why dont u use a list of label?!??
    try to use like this
    i use that for push button

    and u can use sender() function to know which button is pressed for example
    as for ex:
    hope that will help you
    Rondo
    I've tried this solution but it didn't work. The application crash if several labels are created in a very short time.
    Any other ideas ?

    Best Regards,
    Lipos123

  4. #4
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    228

    Re: Re access a label after creating several one with the same name &different object

    u can use a QTimer to accomplish this function
    this will execute the function when it is ready
    i have used it many times and it works great
    Regards,

  5. #5
    Registered User
    Join Date
    Jan 2011
    Posts
    192

    Re: Re access a label after creating several one with the same name &different object

    Thanks Rondo23 for your idea.
    I solved using another method. I have created several label using same name but different ObjectName, and to access a specific label using the objectName i have used findChildren method to search for the label that i want to modify.

    Thanks,
    Best Regards.

Similar Threads

  1. Creating VPN access point
    By suckho in forum Symbian
    Replies: 1
    Last Post: 2010-09-16, 08:26
  2. creating a new access point
    By Digish in forum Symbian
    Replies: 7
    Last Post: 2010-06-01, 11:33
  3. Problem creating custom label
    By amar_wagholikar in forum Symbian User Interface
    Replies: 11
    Last Post: 2009-11-07, 06:59
  4. Creating access point
    By emunokia in forum Symbian Networking & Messaging (Closed)
    Replies: 15
    Last Post: 2007-03-23, 14:39
  5. Creating Label Using J2ME
    By jaceline in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 1
    Last Post: 2006-01-07, 05:12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •