Results 1 to 4 of 4

Thread: Switching between two forms with button click

  1. #1
    Join Date
    Aug 2013
    Posts
    25
    Thanks
    7
    Qt products
    Qt5

    Default Switching between two forms with button click

    Hi

    I have successfully created multiple forms. I know how to switch from form 1 to form 2 on button click using SIGNALS and SLOTS. The problem is when I try switching from form 2 to form 1 it throws an error.

    I have posted a part of the source code.
    This is the first form called measure

    measure.h

    Qt Code:
    1. #ifndef MEASURE_H
    2. #define MEASURE_H
    3.  
    4. #include <QWidget>
    5. #include <readprocess.h>
    6.  
    7.  
    8. namespace Ui {
    9. class measure;
    10. }
    11.  
    12. class measure : public QWidget
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. explicit measure(QWidget *parent = 0);
    18. ~measure();
    19.  
    20. private:
    21. ReadProcess *myProcess;
    22.  
    23. private slots:
    24. void showTime();
    25. void on_pushButton_clicked();
    26. void openReadProcess();
    27.  
    28. private:
    29. Ui::measure *ui;
    30.  
    31. };
    32.  
    33. #endif // MEASURE_H
    To copy to clipboard, switch view to plain text mode 

    measure.cpp

    Qt Code:
    1. #include "measure.h"
    2. #include "ui_measure.h"
    3. #include <QTimer>
    4. #include <QTime>
    5. #include <QDate>
    6.  
    7.  
    8. measure::measure(QWidget *parent) :
    9. QWidget(parent),
    10. ui(new Ui::measure)
    11. {
    12. ui->setupUi(this);
    13.  
    14. }
    15.  
    16. measure::~measure()
    17. {
    18. delete ui;
    19. }
    20.  
    21. void measure::showTime()
    22. {
    23. // some code here
    24. }
    25.  
    26. void measure::openReadProcess()
    27. {
    28. myProcess = new ReadProcess();
    29. this->close();
    30. myProcess->show();
    31. }
    32.  
    33. void measure::on_pushButton_clicked()
    34. {
    35. openReadProcess();
    36. }
    To copy to clipboard, switch view to plain text mode 

    This is the second form called ReadProcess
    Qt Code:
    1. #ifndef READPROCESS_H
    2. #define READPROCESS_H
    3.  
    4. #include <QWidget>
    5. #include <measure.h>
    6.  
    7. namespace Ui {
    8. class ReadProcess;
    9. }
    10.  
    11. class ReadProcess : public QWidget
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit ReadProcess(QWidget *parent = 0);
    17. ~ReadProcess();
    18.  
    19. public slots:
    20. void openMeasure();
    21.  
    22. private:
    23. measure *myMeasureNew;
    24.  
    25. private slots:
    26. void TimingEvent();
    27. void on_abort_clicked();
    28. void updateValue();
    29.  
    30. private:
    31. Ui::ReadProcess *ui;
    32. };
    33.  
    34. #endif // READPROCESS_H
    To copy to clipboard, switch view to plain text mode 

    readprocess.cpp
    Qt Code:
    1. #include "readprocess.h"
    2. #include "ui_readprocess.h"
    3.  
    4.  
    5. ReadProcess::ReadProcess(QWidget *parent) :
    6. QWidget(parent),
    7. ui(new Ui::ReadProcess)
    8. {
    9. ui->setupUi(this);
    10.  
    11. }
    12.  
    13. ReadProcess::~ReadProcess()
    14. {
    15. delete ui;
    16. }
    17.  
    18. void ReadProcess::updateValue()
    19. {
    20. //some code here
    21. }
    22.  
    23. void ReadProcess::TimingEvent()
    24. {
    25. //some code here
    26. }
    27.  
    28. void ReadProcess::openMeasure()
    29. {
    30. myMeasureNew =new measure();
    31. this->close();
    32. myMeasureNew->show();
    33.  
    34. }
    35.  
    36. void ReadProcess::on_abort_clicked()
    37. {
    38. openMeasure();
    39. }
    To copy to clipboard, switch view to plain text mode 

    When I run my application the error thrown is
    'measure' does not name a type
    this error is of readprocess.h following line
    private:
    measure *myMeasureNew;

    Cannot figure out where I am going wrong. Kindly help

  2. #2
    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: Switching between two forms with button click

    In measure.h file, instead of including "readprocess.h" forward declare "class ReadProcess;"
    and include "readprocess.h" in measure.cpp
    Last edited by Santosh Reddy; 30th August 2013 at 12:27.
    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.

  3. The following user says thank you to Santosh Reddy for this useful post:

    gfernandes (30th August 2013)

  4. #3
    Join Date
    Aug 2013
    Posts
    25
    Thanks
    7
    Qt products
    Qt5

    Default Re: Switching between two forms with button click

    Thank you Santosh Reddy Wow! That actually did the trick. But why was my way wrong? Just curiosity sake.. Just a beginner, so wanna learn more.

  5. #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: Switching between two forms with button click

    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.

  6. The following user says thank you to Santosh Reddy for this useful post:

    gfernandes (30th August 2013)

Similar Threads

  1. Problem when switching between forms in QML
    By duc_bkav in forum Qt Programming
    Replies: 0
    Last Post: 24th November 2011, 02:52
  2. Switching between 2 Forms
    By strateng in forum Qt Programming
    Replies: 6
    Last Post: 4th June 2010, 08:09
  3. How can I know which button click.
    By electronicboy in forum Qt Programming
    Replies: 10
    Last Post: 4th October 2009, 14:27
  4. button click in webview
    By mind_freak in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2009, 13:48
  5. DragMode switching based on key & mouse button?
    By mooreaa in forum Qt Programming
    Replies: 1
    Last Post: 1st July 2008, 10: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.