Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: Solving some errors.

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

    Default Solving some errors.

    I am using QtCreator. I am getting this bizaare linker error when i try to combine this app.

    This is what my app is.

    I have made some changes since my last post. This is my code at the moment.

    I need a GUI application to display the contents of myFunction. I have a working console application.

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

    This is my dialog.h
    Qt Code:
    1. #ifndef DIALOG_H
    2. #define DIALOG_H
    3.  
    4. #include <QDialog>
    5.  
    6. class QLabel;
    7. class QPushButton;
    8.  
    9. class FindDialog : public QDialog
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. FindDialog(QWidget *parent = 0);
    15.  
    16. private:
    17. QLabel *disLabel
    18. QPushButton *pushButton;
    19. QWidget *extension;
    20. };
    21.  
    22. #endif // DIALOG_H
    To copy to clipboard, switch view to plain text mode 

    This is my main.cpp

    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. return dialog.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    I am getting the foll errors.

    main.cpp:7: error: `Dialog' was not declared in this scope
    /main.cpp:7: error: expected `;' before "dialog"
    main.cpp:8: error: `dialog' was not declared in this scope
    /main.cpp:7: warning: unused variable 'Dialog'
    /main.cpp:8: warning: unused variable 'dialog'

    How can i solve this?

    thanks for reading.
    Last edited by srohit24; 8th April 2009 at 11:45.

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

    Default Re: Solving a linker error.

    what error did you get?
    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
    143
    Thanks
    8

    Default Re: Solving some errors.

    i have added the errors.

  4. #4
    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.

    you calss is called FindDialog not Dialog according to this
    Qt Code:
    1. #ifndef DIALOG_H
    2. #define DIALOG_H
    3.  
    4. #include <QDialog>
    5.  
    6. class QLabel;
    7. class QPushButton;
    8.  
    9. class FindDialog : public QDialog
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. FindDialog(QWidget *parent = 0);
    15.  
    16. private:
    17. QLabel *disLabel
    18. QPushButton *pushButton;
    19. QWidget *extension;
    20. };
    21.  
    22. #endif // DIALOG_H
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Sep 2007
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 3 Times in 3 Posts

    Default Re: Solving some errors.

    u r defined class with the name "FindDialog".and u r creating object for "Dialog".
    u have not defined class with the name "Dialog",check ur code properly.

  6. #6
    Join Date
    Sep 2007
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 3 Times in 3 Posts

    Default Re: Solving some errors.

    in class "FindDialog" also u have not declared ur slot name called "myFunction1()",it will also create error later.verify total code once and then compile

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

    Default Re: Solving some errors.

    sorry, bad silly mistake. fixed it

    thanks guys fixed the errors.

    I am getting a window, in which there is no label or pushbutton that i am trying to use.

    I have put a label and pushbutton, and have named them according in the .ui file.

    But when i run the app i get a blank window.

    where have i gone wrong??

  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.

    I don't see setupUi(this) in you ctor and I also don't see any Ui::* declaration.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: Solving some errors.

    ok. i have added that as well.

    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. }
    To copy to clipboard, switch view to plain text mode 

    Now i am nt able to make the connection.
    When i press the push button, the text is not being written in the label

  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.

    read post #6.
    add this to h-file
    Qt Code:
    1. ...
    2. public slots:
    3. void myFunction1();
    4. ...
    To copy to clipboard, switch view to plain text mode 
    and also I don't see where you delete ui.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  11. #11
    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 

  12. #12
    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].

  13. #13
    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?

  14. #14
    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?

  15. #15
    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].

  16. #16
    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].

  17. #17
    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?

  18. #18
    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].

  19. #19
    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?

  20. #20
    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].

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

    srohit24 (9th April 2009)

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.