Results 1 to 20 of 29

Thread: Solving some errors.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Solving some errors.

    I have made all the changes you told me to, still the prob exists.

    No link between pushButton and label.

    Qt Code:
    1. #ifndef DIALOG_H
    2. #define DIALOG_H
    3.  
    4. #include <QDialog>
    5.  
    6. class QLabel;
    7. class QPushButton;
    8.  
    9. namespace Ui
    10. {
    11. class DialogClass;
    12. }
    13. class Dialog : public QDialog
    14. {
    15. Q_OBJECT
    16.  
    17. public:
    18. Dialog(QWidget *parent = 0);
    19. ~Dialog();
    20.  
    21. public slots:
    22. void myFunction1();
    23.  
    24. private:
    25. QLabel *disLabel;
    26. QPushButton *pushButton;
    27. Ui::DialogClass *ui;
    28. };
    29.  
    30. #endif // DIALOG_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "dialog.h"
    2. #include "ui_dialog.h"
    3. #include <QLibrary>
    4. #include <QtGui>
    5.  
    6.  
    7.  
    8.  
    9. Dialog::Dialog(QWidget *parent)
    10. : QDialog(parent) ,ui(new Ui::DialogClass)
    11. {
    12.  
    13. ui->setupUi(this);
    14. disLabel = new QLabel;
    15.  
    16. pushButton = new QPushButton(tr("Sync"));
    17. pushButton->setDefault(true);
    18.  
    19. connect(pushButton, SIGNAL(clicked()), this, SLOT(myFunction1()));
    20.  
    21. setWindowTitle(tr("Desktop Uploader"));
    22. }
    23.  
    24.  
    25. void Dialog::myFunction1()
    26. {
    27. QLibrary myLib("dllprog");
    28. typedef char* (*MyPrototype)();
    29. MyPrototype myFunction = (MyPrototype) QLibrary::resolve("dllprog", "TestDll");
    30. char *b = myFunction();
    31. disLabel->setText(tr(b));
    32. }
    33.  
    34. Dialog::~Dialog()
    35. {
    36. delete ui;
    37. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "dialog.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. Dialog dialog;
    8. dialog.show();
    9. return dialog.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: Solving some errors.

    I would change this code
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4. Dialog dialog;
    5. dialog.show();
    6. return dialog.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 
    to that
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4. Dialog dialog;
    5. dialog.show();
    6. return app.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 
    make next things: make clean & qmake & make.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Solving some errors.

    thanks mate.

    Can you explain y i shoulf use app.exec();
    rather than dialog.exec?

  4. #4
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Solving some errors.

    connect(pushButton, SIGNAL(clicked()), this, SLOT(myFunction1()));

    disLabel->setText(tr("b"));

    I am returning a char b in the myFunction1() to check is the connection is working. When irun the app, same prob. no linking.

    where is the mistake?

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: Solving some errors.

    Quote Originally Posted by srohit24 View Post
    thanks mate.

    Can you explain y i shoulf use app.exec();
    rather than dialog.exec?
    when you use app.exec that means that application event loop is started, but in you code when you use dialog.exec means that a dialog event loop is started.

    so, if you want to create an another widget in you dialog and if you close your dialog (after closing event loop will be terminated) that widget which you created will be closed too, but if you use app.exec() that doesn't happen, becuse you don't terminate event loop.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: Solving some errors.

    what kind of error do you get?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Solving some errors.

    Quote Originally Posted by spirit View Post
    what kind of error do you get?
    I am not getting any errors.

    The app is not able to link the button and label in the designer with the actual code in the dialog.cpp.

    Qt Code:
    1. QGridLayout *layout = new QGridLayout;
    2. layout->setColumnStretch(1, 1);
    3. layout->setColumnMinimumWidth(1, 1);
    4. layout->addWidget(syncButton, 0, 0);
    5. layout->addWidget(disLabel, 0, 1);
    6. setLayout(layout);
    7.  
    8. setWindowTitle(tr("Desktop Uploader"));
    9. }
    To copy to clipboard, switch view to plain text mode 

    I had to write this code explicitly so that the label and the button are linked and it shows the desired result.

    how can I solve that?

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: Solving some errors.

    why you don't add these controls (a button and a label) in ui-file in Qt Disigner?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. #9
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Solving some errors.

    I had, but there was no connection between them

    How do i link them to the code?

  10. #10
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: Solving some errors.

    to all controls you can get access using ui->.
    so, you code should look like
    Qt Code:
    1. ...
    2. connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(myFunction1()));
    3. ...
    To copy to clipboard, switch view to plain text mode 
    that's all.
    now you can remove a lable and a pushbutton from class declaration.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  11. The following user says thank you to spirit for this useful post:

    srohit24 (9th April 2009)

  12. #11
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Solving some errors.

    thanks a lot mate. it fixed my problem.


  13. #12
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Solving some errors.

    How can i get the input from the users??

    i have used this code

    Qt Code:
    1. void Dialog::gettext()
    2. {
    3. QString text = QInputDialog::getText(this, tr("Enter the username"),
    4. tr("User name:"), QLineEdit::Normal);
    5. ui->dislabel->setText(text);
    6. }
    To copy to clipboard, switch view to plain text mode 

    but this code pops up a dialog which i dont need.

    What i want is, when i add the text in the lineedit, it should be reflected in the label, or

    when i add the text in the lineedit, a variable names text has to store it.

  14. #13
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: Solving some errors.

    so, you need to add QLineEdit to your form and then
    Qt Code:
    1. ...
    2. connect(ui->lineEdit, SIGNAL(textEdited(const QString &)), ui->label, SLOT(setText(const QString &)));
    3. ...
    To copy to clipboard, switch view to plain text mode 
    this code will add a text from lineEdit to label.

    Qt Code:
    1. ...
    2. connect(ui->pushButton, SIGNAL(clicked()), SLOT(getLineEditText()));//get text by clicking on a button
    3. connect(ui->lineEdit, SIGNAL(editingFinished()), SLOT(getLineEditText()));//get text by pressing enter in a lineEdit
    4. //you can also use QLineEdit::returnPressed insted of QLineEdit::editingFinished
    5. ...
    6.  
    7. void MyWidget::getLineEditText()
    8. {
    9. qDebug() << ui->lineEdit->text();
    10. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 14:43
  2. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 13:57
  3. Error compiling psql plugin
    By vieraci in forum Installation and Deployment
    Replies: 4
    Last Post: 7th October 2007, 03:49
  4. qt 4.2.2 install on aix
    By try to remember in forum Installation and Deployment
    Replies: 2
    Last Post: 28th March 2007, 13:19
  5. Qt-x11-commercial-src-4.2.0-snapshot-20060824 error
    By DevObject in forum Installation and Deployment
    Replies: 4
    Last Post: 25th August 2006, 00:31

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.