Page 2 of 2 FirstFirst 12
Results 21 to 30 of 30

Thread: subclass the QLabel

  1. #21
    Join Date
    Mar 2011
    Posts
    36
    Thanks
    30
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: subclass the QLabel

    guys please figure out this...I am still having problem
    my code are as follows::
    main.cpp
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9. a.installEventFilter(&w);
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    and my mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include "QDebug"
    4. #include "qdebug.h"
    5.  
    6. MainWindow::MainWindow(QWidget *parent) :
    7. QMainWindow(parent),
    8. ui(new Ui::MainWindow)
    9. {
    10. ui->setupUi(this);
    11. ui->label->installEventFilter(this);
    12. }
    13. bool MainWindow::eventFilter(QObject *obj, QEvent *e)
    14. {
    15. if (e->type()==QEvent::MouseButtonPress && obj == ui->label)
    16. {
    17.  
    18. qDebug("User clicked on label");
    19.  
    20. }
    21. return QMainWindow::eventFilter(obj, e);
    22. }
    23. MainWindow::~MainWindow()
    24. {
    25. delete ui;
    26. }
    To copy to clipboard, switch view to plain text mode 

    and mainwindow class
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit MainWindow(QWidget *parent = 0);
    16. ~MainWindow();
    17. bool eventFilter(QObject *obj, QEvent *e);
    18.  
    19. private:
    20. Ui::MainWindow *ui;
    21. };
    22.  
    23.  
    24. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 
    ERROR::cannot open output file ..exe

  2. #22
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: subclass the QLabel

    Is it so hard to note that your application is still running or output directory is read only?
    It is not code problem.

  3. #23
    Join Date
    Mar 2011
    Posts
    36
    Thanks
    30
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: subclass the QLabel

    Is it so hard to note that your application is still running or output directory is read only?
    It is not code problem.
    no my application is not running at all neither the directory is read only

  4. #24
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: subclass the QLabel

    Then you have to discover yourself why linker doesn't have access to this file. I've given you to most common reasons.

  5. The following user says thank you to MarekR22 for this useful post:

    ready (25th March 2011)

  6. #25
    Join Date
    Mar 2011
    Posts
    36
    Thanks
    30
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: subclass the QLabel

    please try to run and see above code in your ui application
    and provide me help

  7. #26
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: subclass the QLabel

    please provide the *.ui-file, otherwise we can't test your code...

    edit @mods: why was this thread moved? It is quite Qt-specific, isn't it?

  8. The following user says thank you to FelixB for this useful post:

    ready (25th March 2011)

  9. #27
    Join Date
    Mar 2011
    Posts
    36
    Thanks
    30
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: subclass the QLabel

    mu ui file contains only line edit and label
    Last edited by ready; 25th March 2011 at 16:51.

  10. #28
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: subclass the QLabel

    Ok, but the more work we have to do in order to help you, the less chance you have of actually receiving any help

  11. #29
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: subclass the QLabel

    Sorry, I really can't stop myself. I've seen this from the very beginning but I tried to wait and see how the thread develops but I can't resist anymore from asking, what's the purpose of the two following lines together?

    Qt Code:
    1. ui->label->installEventFilter(this); // in MainWindow
    2. a.installEventFilter(&w); // in main
    To copy to clipboard, switch view to plain text mode 

    I'd like the OP to explain what was the intention behind those two lines.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #30
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: subclass the QLabel

    hi ready,
    as wysota mentioned, you need to remove a.installEventFilter(&w); in main.
    same code u posted working for me, try to clean and make agian.

    hope it helps,
    bala

Similar Threads

  1. Replies: 8
    Last Post: 12th February 2010, 02:41
  2. Replies: 1
    Last Post: 29th September 2009, 19:44
  3. Replies: 1
    Last Post: 2nd August 2008, 15:46
  4. Subclass Pushbutton
    By Smith in forum Newbie
    Replies: 6
    Last Post: 8th December 2007, 12:56
  5. Subclass
    By merry in forum General Programming
    Replies: 2
    Last Post: 1st March 2007, 10:34

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.