Results 1 to 4 of 4

Thread: What am i doing wrong?

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default What am i doing wrong?

    The code below is suppose to display a label on a window but it doesn't, instead it displays a blank window. what am I doing wrong. Please help.

    #ifndef PAYCLASS_H
    #define PAYCLASS_H
    #include <QMainWindow>
    #include <QObject>
    #include <QPushButton>
    #include <QGridLayout>
    #include <QLabel>
    #include <QTextEdit>
    #include <QDate>
    #include <QCalendarWidget>
    #include <QTimeEdit>
    #include <QHBoxLayout>

    class PayClass : public QMainWindow
    {
    Q_OBJECT
    public:
    explicit PayClass();
    double calculateHrs(int numOfHrs);
    double calculatePay();

    signals:

    public slots:
    private:
    QPushButton* Calculate;
    QGridLayout* Layout;
    QHBoxLayout* HLayout;
    QLabel* Label1, *Label2, *Label3, *Label4, *Mon, *Tue, *Wed, *Thur, *Fri, *Sat;
    QTextEdit* txtEdit1, *txtEdit2;
    QDate *dateOnDuty;
    QCalendarWidget* Calender;
    QTimeEdit* Time1, *StartOfLunch, *endOfLunch, *Time3;


    };

    #endif // PAYCLASS_H

    #include <QtGui/QApplication>
    #include "payclass.h"

    int main(int argc, char* argv[])
    {
    QApplication App(argc, argv);
    PayClass myApp;

    myApp.show();

    system("PAUSE");

    return 0;
    }

    #include "payclass.h"

    PayClass::PayClass()
    {
    setWindowTitle("My Hours");

    Label1 = new QLabel("Clocking In Time");
    Label2 = new QLabel("Start Of Lunch");
    Label3 = new QLabel("End Of Lunch");
    Label4 = new QLabel("Clocking Out Time");

    Calculate = new QPushButton("Calculate");



    HLayout = new QHBoxLayout();
    Layout = new QGridLayout();

    Layout->addWidget(Label1, 0, 0);

    setLayout(Layout);


    }

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am i doing wrong?

    Instead of
    Qt Code:
    1. system("PAUSE");
    2. return 0;
    To copy to clipboard, switch view to plain text mode 
    use
    Qt Code:
    1. return App.exec();
    To copy to clipboard, switch view to plain text mode 
    You need a working event loop.

  3. #3
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What am i doing wrong?

    I've done that and it still doesn't work.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: What am i doing wrong?

    PayClass is derivered from QMainWindow. QMainWindow has a special Layout. So Replace this code
    Qt Code:
    1. PayClass::PayClass()
    2. {
    3. ...
    4. setLayout(Layout); // <<<<<<<<<<<<<<<<<<<<<< Remove
    5. }
    To copy to clipboard, switch view to plain text mode 
    with
    Qt Code:
    1. PayClass::PayClass()
    2. {
    3. ...
    4. // <<<<<<<<<<<<<<<<<<<<<< Add following
    5. QWidget * widget = new QWidget(this);
    6. widget->setLayout(Layout);
    7. setCentralWidget(widget);
    8. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. I`m doing it wrong....
    By KillGabio in forum Newbie
    Replies: 13
    Last Post: 13th February 2012, 01:58
  2. What am I doing wrong??
    By Splatify in forum Newbie
    Replies: 3
    Last Post: 7th February 2011, 16:47
  3. What do I do wrong
    By Arif Bilgin in forum Newbie
    Replies: 12
    Last Post: 20th October 2010, 20:03
  4. i don't know what i do wrong..
    By Hardstyle in forum Newbie
    Replies: 2
    Last Post: 27th June 2010, 17:33
  5. Help please - what am I doing wrong?
    By Jimmy2775 in forum Qt Programming
    Replies: 6
    Last Post: 6th March 2006, 22:06

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.