Results 1 to 5 of 5

Thread: Problem accesing widgets

  1. #1
    Join Date
    Feb 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem accesing widgets

    Hi, I'm really new to QT and c++ and was doing something with QTcreator I designed a ui, and I tried to put some functionality in it by modifiyng the cpp from the ui.

    Qt Code:
    1. #include "cliente.h"
    2. #include "ui_cliente.h"
    3. #include "QDialogButtonBox"
    4.  
    5.  
    6. Cliente::Cliente(QWidget *parent)
    7. : QMainWindow(parent), ui(new Ui::ClienteClass)
    8. {
    9.  
    10.  
    11. ui->setupUi(this);
    12.  
    13. QString text = ui->direccionLE->text();
    14.  
    15. connect(ui->conectarB, SIGNAL(clicked()),this, SLOT(accion()));
    16.  
    17. }
    18.  
    19. void accion(){
    20. //
    21. QString text = ui->direccionLE->text();
    22.  
    23.  
    24.  
    25. }
    26.  
    27. Cliente::~Cliente()
    28. {
    29. delete ui;
    30.  
    31. }
    To copy to clipboard, switch view to plain text mode 
    The problem is that I can't acces say (QString text = ui->direccionLE->text();) in the function accion because ui is not declared in that scope, I know this might be a really stupid question, bur how do I acces widgets from the ui in a function (lineedits, comboboxes, ...)

    Thanks for your patience
    Last edited by jpn; 6th February 2009 at 14:08. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem accesing widgets

    Qt Code:
    1. void accion() {
    2. QString text = ui->direccionLE->text();
    3.  
    4. }
    To copy to clipboard, switch view to plain text mode 
    You are defining here a global finction wich has nothing to do with your class Cliente.

    You should do it like this:
    Qt Code:
    1. void Cliente::accion() {
    2. QString text = ui->direccionLE->text();
    3. }
    To copy to clipboard, switch view to plain text mode 
    Notice that "Cliente::" before "accion()", in simple way - it's necessary to tell that your accion() is from Cliente class (I hope you declared it in class declaration...)

    Anyway, these are basics of C++ language so get some C++ book/tutorial.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. #3
    Join Date
    Feb 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem accesing widgets

    Thank you very much.

    now everything builds and compiles fine but...

    Qt Code:
    1. void Cliente::accion(){
    2. ui->direccionLE->setText("Some Text");
    3. ui->consulta1L->setText("text");
    4. ui->consulta1LE->setText("prueba");
    5. }
    To copy to clipboard, switch view to plain text mode 

    when I try my code it does't seem to change the values in the ui, why's that?
    Last edited by jpn; 6th February 2009 at 14:11. Reason: missing [code] tags

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem accesing widgets

    what do u mean by "try my code" ?

    You have connected accion with ui->conectarB. Are you pressing the button ?

  5. #5
    Join Date
    Feb 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem accesing widgets

    Ok, by try I mean, when I execute the code and press the button connected to the function nothing changes in the QlineEdits and labesl that are supposed to change.

Similar Threads

  1. Problem of including Widgets into DLL
    By dsedov in forum Qt Programming
    Replies: 15
    Last Post: 14th July 2021, 23:05
  2. Accesing widgets from separate thread
    By msmihai in forum Qt Programming
    Replies: 2
    Last Post: 8th December 2008, 11:48
  3. Replies: 0
    Last Post: 16th July 2008, 13:15
  4. Docking widgets setFixedSize and setBaseSize Problem
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2006, 18:20
  5. Replies: 11
    Last Post: 7th July 2006, 13:09

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.