Results 1 to 9 of 9

Thread: Trying to show a QDialog

  1. #1
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Trying to show a QDialog

    Hello,

    Trying to show a QDialog, but I am getting the errors shown.
    What am I doing wrong?

    Regards

    Qt Code:
    1. Header
    2. #ifndef QG_DIVIDEOPTIONS_H
    3. #define QG_DIVIDEOPTIONS_H
    4.  
    5. #include <QDialog>
    6.  
    7. namespace Ui {
    8. class qg_divideoptions;
    9. }
    10.  
    11. class qg_divideoptions : public QDialog
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit qg_divideoptions(QWidget *parent = 0);
    17. ~qg_divideoptions;
    18.  
    19. private:
    20. Ui::qg_divideoptions *ui;
    21.  
    22. };
    23. #endif // QG_DIVIDEOPTIONS_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. qg_divideoptions.cpp
    2. #include <QtGui>
    3. #include "qg_divideoptions.h"
    4.  
    5. qg_divideoptions::qg_divideoptions(QWidget *parent) : //*** qg_divideoptions does not name a type
    6. QDialog(parent),
    7. ui(new Ui::qg_divideoptions)
    8. {
    9. ui->setupUi(this);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. Calling function header
    2. public:
    3. QDialog* mydialog;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. Calling function
    2. #include "qg_divideoptions.h"
    3. #include <QDialog>
    4.  
    5. void myfunc::mouseReleaseEvent(QMouseEvent* e) {
    6. if (e->button() == Qt::LeftButton) {
    7. qg_divideoptions mydialog = new qg_pdivideoptions(); //*** qg_divideoptions was not declared in this scope
    8. mydialog->show(); //*** mydialog was not declared in this scope
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Trying to show a QDialog

    I can't see any syntactic problems with this code that could cause this problem. The only thing I can think of is you have two files called "qg_divideoptions.h", one of which is empty or does not contain the definition of your class, and that is the one being #include-ed by mistake. Or, because lowercase "q" and "g" look so similar, you might have a "q" where a "g" should be (or vice-versa) and you don't see it because you have to look very closely at the text to tell the two apart. "qq", "qg", "gq", and "gg" all look pretty much the same if you aren't looking carefully. I would choose a different name to make maintenance and debugging easier.

    In your mouseReleaseEvent, you have a memory leak. Each time this event executes, you are creating new copy of the dialog and assigning it to a local variable in the function. Once the function exits, you have a dangling pointer that isn't accessible for you to delete the dialog instance later.

    Better is to create the dialog on the stack and execute it as a modal dialog:

    Qt Code:
    1. void myfunc::mouseReleaseEvent(QMouseEvent* e) {
    2. if (e->button() == Qt::LeftButton) {
    3. qg_divideoptions mydialog( this );
    4. if ( QDialog::Accepted == mydialog.exec() )
    5. // do something with the result
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    Of course, if I were a user of your software and this *^%&@ dialog kept popping up every time I clicked the mouse button by accident I'd probably become an ex-user pretty quickly. Maybe something more user-friendly, like a context menu that let me choose to show the dialog would be nicer.
    Last edited by d_stranz; 16th September 2017 at 16:52.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Trying to show a QDialog

    Hello d_stranz,

    Thanks for your reply.

    "qq", "qg", "gq", and "gg" all look pretty much the same
    Yes I know, its somebody elses program, I'm stuck with it.

    *^%&@ dialog kept popping up every time
    There are checks in place, as to when its allowed to pop up.

    The two files bit, turns out it was a suspect HDD data lead, was editing the wrong file.

    Your point is noted about show() and exec().

    I will know in about 7 hours, doing a rebuild.

    Regards

  4. #4
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Trying to show a QDialog

    Hello.

    Back on this now.
    I did a fresh build and got the following errors.
    Help Please!

    Regards

    Qt Code:
    1. #ifndef QG_DIVIDEOPTIONS_H
    2. #define QG_DIVIDEOPTIONS_H
    3.  
    4. #include <QDialog>
    5. //#include <ui_qg_divideoptions.h>
    6.  
    7. namespace Ui {
    8. class qg_divideoptions;
    9. }
    10.  
    11. class qg_divideoptions : public QDialog
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit qg_divideoptions(QWidget *parent = 0);
    17. ~qg_divideoptions();
    18.  
    19. private:
    20. Ui::qg_divideoptions *ui;
    21.  
    22. signals:
    23.  
    24. private slots:
    25. };
    26. #endif // QG_DIVIDEOPTIONS_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include <QtGui>
    2. #include <QDialog>
    3.  
    4. #include "qg_divideoptions.h" //this is qg_divideoptions.cpp:29
    5. #include <ui_qg_divideoptions.h>
    6.  
    7. qg_divideoptions::qg_divideoptions(QWidget *parent) :
    8. QDialog(parent),
    9. ui(new Ui::qg_divideoptions) // invalid use of incomplete type 'class Ui::qg_divideoptions'
    10. // In file included from ...\qg_divideoptions.cpp:29:
    11. // forward declaration of 'class Ui::qg_divideoptions'
    12. {
    13. ui->setupUi( this ); // invalid use of incomplete type 'class Ui::qg_divideoptions'
    14. // In file included from ...\qg_divideoptions.cpp:29:
    15. // forward declaration of 'class Ui::qg_divideoptions'
    16. }
    17.  
    18. qg_divideoptions::~qg_divideoptions()
    19. {
    20. //saveSettings();
    21. qDebug() << "end";
    22. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Trying to show a QDialog

    It indicates that the "qg_divideoptions.ui" file (or the ui_qg_divideoptions.h" file generated from it by the resource compiler) is wrong.

    I think you need to spend some time cleaning up your project and file environment and making sure that the duplicate copies of things you seem to have laying around are gone and that your project and the include paths points to the right files in the right locations.

    Your use of "#include <ui_qg_divideoptions.h>" instead of "#include "ui_qg_divideoptions.h"" is a red flag. When you use "<>" instead of quotes, it is telling the compiler not to look in the current directory for a file, but to look somewhere else along the list of include paths. That tells me the compiler is probably using the wrong file.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. #6
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Trying to show a QDialog

    Hello,

    Thanks for your help.
    My main problem was a dying mother board (fixed now) and
    the rest of the problem is my ignorance.
    I created a new source directory and compiled from there.

    I've still got problems, that I don't understand.

    Regards
    Qt Code:
    1. Call
    2. qg_divideoptions mydialog( 0 );// this );
    3. //using 'this' :-
    4. //error: no matching function for call to
    5. //'qg_divideoptions::qg_divideoptions(RS_ActionModifyCut*)'
    6. //'RS_ActionModifyCut' is the function the above call is in.
    7.  
    8. if ( QDialog::Accepted == mydialog.exec() )
    9. {
    10. // do something with the result
    11. qDebug() << "accepted";
    12. }
    13. else
    14. {
    15. qDebug() << "rejected";
    16. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. Header
    2.  
    3. #ifndef QG_DIVIDEOPTIONS_H
    4. #define QG_DIVIDEOPTIONS_H
    5.  
    6. #include <QtGui>
    7. #include <QDialog>
    8.  
    9.  
    10. namespace Ui {
    11. class qg_divideoptions; //forward declaration of 'class Ui::qg_divideoptions'
    12. }
    13.  
    14. class qg_divideoptions : public QDialog
    15. {
    16. Q_OBJECT
    17.  
    18. public:
    19. qg_divideoptions(QWidget *parent = 0);
    20. ~qg_divideoptions();
    21.  
    22. private:
    23. Ui::qg_divideoptions *ui;
    24.  
    25. signals:
    26.  
    27. private slots:
    28.  
    29. }
    30.  
    31. #endif // QG_DIVIDEOPTIONS_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. qg_divideoptions.cpp
    2.  
    3. #include <QtGui>
    4.  
    5. #include <QDialog>
    6. #include <QWidget>
    7.  
    8. #include "qg_divideoptions.h"
    9. #include <QDebug>
    10.  
    11.  
    12. qg_divideoptions::qg_divideoptions(QWidget *parent) :
    13. QDialog(parent),
    14. ui(new Ui::qg_divideoptions) //error: invalid use of incomplete type 'class Ui::qg_divideoptions'
    15. {
    16. ui->setupUi(this); //error: invalid use of incomplete type 'class Ui::qg_divideoptions'
    17. }
    18.  
    19. qg_divideoptions::~qg_divideoptions()
    20. {
    21. qDebug() << "deleted";
    22. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. qg_divideoptions.ui
    2.  
    3. <?xml version="1.0" encoding="UTF-8"?>
    4. <ui version="4.0">
    5. <class>divodeoptions</class>
    6. <widget class="QDialog" name="divodeoptions">
    7. <property name="geometry">
    8. <rect>
    9. <x>0</x>
    10. <y>0</y>
    11. <width>400</width>
    12. <height>300</height>
    13. </rect>
    14. </property>
    15. <property name="windowTitle">
    16. <string>Divide Options</string>
    17. </property>
    18. </widget>
    19. <resources/>
    20. <connections/>
    21. </ui>
    To copy to clipboard, switch view to plain text mode 
    Last edited by jimbo; 29th September 2017 at 14:03.

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Trying to show a QDialog

    ui(new Ui::qg_divideoptions) //error: invalid use of incomplete type 'class Ui::qg_divideoptions'

    ui->setupUi(this); //error: invalid use of incomplete type 'class Ui::qg_divideoptions'
    You haven't #include'd the ui_...h file for your ui class. You forward-declared it in the header file, but never included the file that contains the implementation.

    I have no idea what is causing the first error. You haven't included the full source code for the function, so there is no information about the context in which you are trying to create your dialog.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. #8
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Trying to show a QDialog

    Hello,

    Again thanks for your help.

    Windows 10 - 32bit

    I'm building from within Qt Creator.

    About:-
    Qt Creator 4.4.0
    Based on Qt 5.9.1 (MSVC 2015, 32 bit)

    gcc version 5.3.0 (i686-posix-dwarf-rev0, Built by MinGW-W64 project)

    Still getting the same errors,

    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include <QDialog>
    4. #include <QWidget>
    5.  
    6. #include "qg_divideoptions.h"
    7. #include "ui_qg_divideoptions.h" //*** added
    8. #include <QDebug>
    9.  
    10. qg_divideoptions::qg_divideoptions(QWidget *parent) :
    11. QDialog(parent),
    12. ui(new Ui::qg_divideoptions)
    13. {
    14. ui->setupUi(this);
    15. }
    16.  
    17. qg_divideoptions::~qg_divideoptions()
    18. {
    19. qDebug() << "deleted";
    20. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. rs_actionmodifycut.h
    2.  
    3. private:
    4. QDialog *mydialog;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. rs_actionmodifycut.cpp
    2.  
    3. #include "rs_actionmodifycut.h"
    4.  
    5. #include <QAction>
    6. #include <QMouseEvent>
    7. #include "rs_dialogfactory.h"
    8. #include "rs_graphicview.h"
    9. #include "rs_modification.h"
    10. #include "rs_debug.h"
    11.  
    12. //*** ***
    13. #include <QDialog>
    14. #include <QDebug>
    15. #include "qg_divideoptions.h"
    16. //*** ***
    17.  
    18. RS_ActionModifyCut::RS_ActionModifyCut(RS_EntityContainer& container,
    19. RS_GraphicView& graphicView)
    20. :RS_ActionInterface("Cut Entity",
    21. container, graphicView)
    22. ,cutEntity(nullptr)
    23. ,cutCoord(new RS_Vector{})
    24. {
    25. actionType=RS2::ActionModifyCut;
    26. }
    27.  
    28. void RS_ActionModifyCut::mouseReleaseEvent(QMouseEvent* e) {
    29. if (e->button()==Qt::LeftButton) {
    30. switch (getStatus()) {
    31. case ChooseCutEntity:
    32. cutEntity = catchEntity(e);
    33. if (cutEntity==nullptr) {
    34. RS_DIALOGFACTORY->commandMessage(tr("No Entity found."));
    35. } else if(cutEntity->trimmable()){
    36. cutEntity->setHighlighted(true);
    37. graphicView->drawEntity(cutEntity);
    38. setStatus(SetCutCoord);
    39.  
    40. //*** ***
    41. qg_divideoptions mydialog( 0 );// this );
    42.  
    43. if ( QDialog::Accepted == mydialog.exec() )
    44. {
    45. // do something with the result
    46. qDebug() << "accepted";
    47. }
    48. else
    49. {
    50. qDebug() << "rejected";
    51. }
    52. //*** ***
    53.  
    54. }else
    55. RS_DIALOGFACTORY->commandMessage(
    56. tr("Entity must be a line, arc, circle, ellipse or interpolation spline."));
    57. break;
    58.  
    59. case SetCutCoord:
    60. *cutCoord = snapPoint(e);
    61. if (cutEntity==nullptr) {
    62. RS_DIALOGFACTORY->commandMessage(tr("No Entity found."));
    63. } else if (!cutCoord->valid) {
    64. RS_DIALOGFACTORY->commandMessage(tr("Cutting point is invalid."));
    65. } else if (!cutEntity->isPointOnEntity(*cutCoord)) {
    66. RS_DIALOGFACTORY->commandMessage(
    67. tr("Cutting point is not on entity."));
    68. } else {
    69. trigger();
    70. deleteSnapper();
    71. }
    72.  
    73. qDebug() << "released";
    74. break;
    75.  
    76. default:
    77. break;
    78. }
    79. } else if (e->button()==Qt::RightButton) {
    80. if (cutEntity) {
    81. cutEntity->setHighlighted(false);
    82. graphicView->drawEntity(cutEntity);
    83. }
    84. init(getStatus()-1);
    85. }
    86. }
    87.  
    88. //Rest of the functions
    89. ...
    90. ...
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Trying to show a QDialog

    rs_actionmodifycut.h
    I should be paid as much as my dentist - I am spending almost as much time pulling teeth here. What Qt class is "RS_ActionModifyCut" ultimately derived from?

    Look, it is basic C++: any QWidget-based class takes an optional pointer to its parent QWidget as an argument to its constructor. This includes QDialog and classes derived from QDialog. If you try to pass in a pointer to a class that is not derived from QWidget, then you will get a compile-time error. Passing "0" always works, because a zero can be cast to a pointer of any type. Passing "this" will work only if the class that "this" is an instance of is derived ultimately from QWidget.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 9
    Last Post: 25th March 2011, 21:22
  2. How to show a QDialog ( Designed ) ?
    By Bong.Da.City in forum Newbie
    Replies: 18
    Last Post: 17th August 2010, 20:01
  3. How to show a QDialog ( Designed ) ?
    By Bong.Da.City in forum Qt Programming
    Replies: 5
    Last Post: 17th August 2010, 16:54
  4. use QDialog to show file name
    By damonlin in forum Qt Programming
    Replies: 3
    Last Post: 16th November 2008, 13:52
  5. can't show my QDialog
    By sincnarf in forum Qt Programming
    Replies: 3
    Last Post: 22nd October 2007, 09:33

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.