Results 1 to 17 of 17

Thread: Can not access the QLineEdit text within the QDialog

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can not access the QLineEdit text within the QDialog

    Hi,

    There is no use of "func()" it was included by mistake. I have included the line "Dname->exec();", But i get the error "the class has no member named exec(). I am trying to understand the second method.

    Thank you,
    Baluk

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Can not access the QLineEdit text within the QDialog

    There is but
    Qt Code:
    1. name::name(QWidget *parent) :
    2. QObject(parent)
    To copy to clipboard, switch view to plain text mode 
    should be
    Qt Code:
    1. name::name(QWidget *parent) :
    2. QDialog(parent)
    To copy to clipboard, switch view to plain text mode 
    like you have declared it.

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Can not access the QLineEdit text within the QDialog

    Qt Code:
    1. name::name(QWidget *parent) :
    2. QObject(parent)
    To copy to clipboard, switch view to plain text mode 

    Is wrong. You need to inherit from QDialog to get the exec() function.

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Can not access the QLineEdit text within the QDialog

    Use show() in the place for exec() (QMainWindow doesn't have exec() only QDialog has) and use setWindowModality(...) to make it Modal if you really need a modal window.

  5. #5
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can not access the QLineEdit text within the QDialog

    Hi,

    Now I got it working very fine . I am thankful to all of you especially to Lykurg for bearing me .

    Thank you,
    Baluk

  6. #6
    Join Date
    Dec 2010
    Posts
    71
    Thanks
    26
    Platforms
    Windows

    Default Re: Can not access the QLineEdit text within the QDialog

    Hi,

    I'm having a similar problem over a week... I tried everything... Created an Ui Form, created that form on code and both ways I can't get the QLineEdit to show it's text() value.

    Everything compiles fine and when running a function within the same class a the Widget was created, I keep getting an empty string when something is written on the lineEdit field on this function here:

    Qt Code:
    1. void teacherChatMain::returnPressedFunc()
    2. {
    3. QString text = lineEdit->text(); //allways returns ""
    4. if (text.isEmpty())
    5. return;
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 

    here is my constructor: (this is a plugin, I'll post 1st the mainWindow code then the plug in code)

    //MainWindow code

    bool mainWindow::instantiateTeacherChatPlugin( QObject * plugin )
    {
    iTChat = qobject_cast<ITeacherChat *>( plugin );
    if(iTChat)
    {
    iTChat->initialize();
    iTChat->setParentWidget(this);
    m_iTChat = plugin;
    chatTimerPull = new QTimer();
    return true;
    }
    return false;
    }

    Qt Code:
    1. void teacherChatMain::initialize( void )
    2. {
    3. scrollArea = new QScrollArea();
    4. }
    5.  
    6. void teacherChatMain::startWorking( void )
    7. {
    8. winChatWidget = new QWidget;
    9. winChatWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    10. winChatWidget->setMaximumWidth(350);
    11.  
    12. gridLayout = new QGridLayout;
    13.  
    14. stuNameLbl = new QLabel("",winChatWidget);
    15. stuNameLbl->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    16. stuNameLbl->setMinimumSize(368,20);
    17.  
    18. gridLayout->addWidget(stuNameLbl, 0, 0, 0, 1);
    19.  
    20. closeBt = new QPushButton(winChatWidget);
    21. closeBt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    22. closeBt->setFixedSize(20, 20);
    23.  
    24. closeBt->setIcon(QIcon(":/resources/cancelar.png"));
    25. closeBt->setIconSize(QSize(16, 16));
    26.  
    27. gridLayout->addWidget(closeBt, 0, 2);
    28.  
    29. textEdit = new QTextEdit(winChatWidget);
    30. textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    31. textEdit->setFocusPolicy(Qt::NoFocus);
    32. textEdit->setMinimumSize(394,450);
    33.  
    34. gridLayout->addWidget(textEdit, 1, 0, 1, 1);
    35.  
    36. messageLbl = new QLabel(tr("Mensagem: "),winChatWidget);
    37. messageLbl->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    38. messageLbl->setMinimumWidth(80);
    39. messageLbl->setMaximumWidth(80);
    40. gridLayout->addWidget(messageLbl, 2, 0);
    41.  
    42. lineEdit = new QLineEdit(winChatWidget);
    43. messageLbl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    44. lineEdit->setFocusPolicy(Qt::StrongFocus);
    45. lineEdit->setMinimumSize(307,20);
    46. gridLayout->addWidget(lineEdit, 2, 1);
    47.  
    48. closeBt->setVisible(false);
    49. stuNameLbl->setVisible(false);
    50.  
    51. tableFormat.setBorder(0);
    52.  
    53. connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressedFunc()));
    54.  
    55.  
    56. winChatWidget->setLayout(gridLayout);
    57. setTeacherName(_parent->getTeacherName());
    58.  
    59. setActive(false);
    60.  
    61. connect(this, SIGNAL(newMessage(QString,QString)),
    62. this, SLOT(appendMessage(QString,QString)));
    63.  
    64. stGridDlg = new studentsGridDialog(this, studentsScrollArea,_parent->getLoggedStudents(), _parent->getTeacherName(), windowChatScrollArea);
    65. QObject::connect(stGridDlg, SIGNAL(newMessageReceived()), this, SLOT(newMessageReceived()));
    66. connect(this, SIGNAL(returnPressedMsg(QString, QString)), stGridDlg, SIGNAL(returnPressedSignal(QString, QString)));
    67.  
    68.  
    69. contentsLayout->addWidget(studentsScrollArea,0,0);
    70. contentsLayout->addWidget(winChatWidget,0,1);
    71.  
    72. scrollArea->setLayout(contentsLayout);
    73. }
    To copy to clipboard, switch view to plain text mode 

    Please can some one help me? I'm about to try my next step which is throwing the computer out of the window!!!

Similar Threads

  1. I cannot get the string from QLineEdit->text()!
    By MIH1406 in forum Qt Programming
    Replies: 0
    Last Post: 3rd June 2010, 11:26
  2. cannot access QLineEdit text in other methods of the class...
    By Leoha_Zveri in forum Qt Programming
    Replies: 2
    Last Post: 29th September 2009, 12:07
  3. Setting the text of a QLineEdit
    By td in forum Newbie
    Replies: 2
    Last Post: 11th September 2008, 11:03
  4. Text before editting on QLineEdit
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 8th September 2008, 15:51
  5. QLineEdit text() crash - Qt3
    By user_mail07 in forum Qt Programming
    Replies: 7
    Last Post: 10th June 2008, 09:42

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
  •  
Qt is a trademark of The Qt Company.