Results 1 to 4 of 4

Thread: Simple error :P

  1. #1
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Simple error :P

    I've created a form named startno. Inside I have a QLineEdit object named line. I would like to change text in this field by writing code into startno.ui.h.

    If I use it inside a function (like after button click) it works ok. Working example:
    Qt Code:
    1. void startno::changeso_clicked()
    2. {
    3. line->setText("test1");
    4. }
    To copy to clipboard, switch view to plain text mode 

    If I try to write text to that field outside of any function I get an error. Non-working example:
    Qt Code:
    1. line->setText("test1");
    To copy to clipboard, switch view to plain text mode 


    I know I can set this text in property editor. But I would like to find a solution for this for future

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Simple error :P

    This is really a C++ issue. You have to follow C++ rules for accessing objects. If "line" is a member of class "startno" you have to access it using an object of class "startno" and not as a "hanging in void" object "line".

  3. #3
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Simple error :P

    maybe it will help you if you set the text in the constructor of the form (at the ui.h file it is the init() function), simply create it

    Qt Code:
    1. void startno::init()
    2. {
    3. line->setText("test1");
    4. }
    To copy to clipboard, switch view to plain text mode 

    then your text will be set upon creation of the form.
    ..:: Still Standing Strong ::..

  4. #4
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Simple error :P

    Or . U could use the designer to set the text initially.

    Generally It's good not to use the ui.h approach, rather use the subclassing one.

    U will find help on this approach in the designers man pages.

    under the section Subclassing and Dynamic Dialogs

    We can't solve problems by using the same kind of thinking we used when we created them

Similar Threads

  1. Simple way to expand all nodes on a QTreeView?
    By cboles in forum Qt Programming
    Replies: 10
    Last Post: 12th April 2014, 16:54
  2. QTextEdit simple question
    By Marcopolo in forum Qt Tools
    Replies: 4
    Last Post: 11th October 2007, 00:01
  3. Release my simple program to other users ?
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 9th July 2006, 23:42
  4. Simple example with painting
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 18th March 2006, 13:15
  5. can't get a simple dialog working
    By pthomas in forum Newbie
    Replies: 8
    Last Post: 13th January 2006, 14:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.