Results 1 to 4 of 4

Thread: Transfer the values entered in one line edit to another present in different window

  1. #1
    Join Date
    Feb 2018
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Transfer the values entered in one line edit to another present in different window

    The mainwindow header looks like:
    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit MainWindow(QWidget *parent = 0);
    7. bool eventFilter(QObject *obj, QEvent *event);
    8. ~MainWindow();
    9.  
    10. private:
    11. Ui::MainWindow *ui;
    12. connection *con;
    13. };
    To copy to clipboard, switch view to plain text mode 

    Mainwindow source looks like:


    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. ui->lineEdit->installEventFilter(this);
    8. QObjectList o_list = ui->lineEdit->children();
    9. for(int i = 0; i < o_list.length(); i++)
    10. {
    11. QLineEdit *cast = qobject_cast<QLineEdit*>(o_list[i]);
    12. if(cast)
    13. cast->installEventFilter(this);
    14. }
    15.  
    16. }
    17.  
    18.  
    19.  
    20. bool MainWindow::eventFilter(QObject *obj, QEvent *event)
    21. {
    22. if(event->type() == QEvent::MouseButtonPress)
    23. {
    24. con->show();
    25. }
    26. return false;
    27. }
    28.  
    29.  
    30. MainWindow::~MainWindow()
    31. {
    32. delete ui;
    33. }
    To copy to clipboard, switch view to plain text mode 

    the Ui window contains a lineedit each.the connection window contains a textbox and the mainwindow contains another.The objective is to transfer the string/data from the widget window to main window using connect or any other method.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Transfer the values entered in one line edit to another present in different wind

    So, are you giving us assignments or what?

    What is the problem you have, what help do you need?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2018
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Transfer the values entered in one line edit to another present in different wind

    thank you for suggesting about S.O.L.I.D. I'm just a beginner and haven't used Qt much.I just want to know that if we want to transfer values written in lineedit present in a widget opened from mainwindow, to a lineedit present in mainwindow.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Transfer the values entered in one line edit to another present in different wind

    The S.O.L.I.D principles information is part of my signature, not the post :-)

    The way you write, and your code suggests you don't really understand basic C++.
    The answer to your question would be that the information of your UI should be held separately from the UI, thus available to any UI part in your application.

    In your code, you have a member variable 'connection' which is not initialized (so it will probably crash in your eventFilter() and its not visible where you destroy it either.

    Before you start working with a tool kit like Qt, better start with basic C++ on basic concepts of OOP.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. QTableView line edit clears the text on edit
    By PlasticJesus in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 20:06
  2. How to present a Qt GUI app window to users???
    By wshn13 in forum Qt Programming
    Replies: 4
    Last Post: 29th August 2011, 10:34
  3. Replies: 10
    Last Post: 13th March 2011, 00:07
  4. Replies: 3
    Last Post: 26th August 2010, 09:57
  5. Replies: 28
    Last Post: 7th May 2010, 13:29

Tags for this Thread

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.