Results 1 to 3 of 3

Thread: I want to open a QFileDialog, but this code does not open it.

  1. #1
    Join Date
    Jul 2014
    Posts
    95
    Thanks
    67

    Default I want to open a QFileDialog, but this code does not open it.

    Hello, I want to open a QFileDialog, but this code does not open it.why? thank you.
    Qt Code:
    1. #include <QtWidgets>
    2. #include "widget.h"
    3. widget::widget()
    4. {
    5. text=new QTextEdit;
    6. resize(250,250);
    7. setCentralWidget(text);
    8. createaction();
    9. createmenu();
    10. createStatusBar();
    11. }
    12. void widget::createmenu()
    13. {
    14. filemenu=menuBar()->addMenu(tr("File"));
    15. filemenu->addAction(newact);
    16. }
    17. void widget::createaction()
    18. {
    19. newact=new QAction(tr("&Open"),this);
    20. newact->setShortcut(QKeySequence::Open);
    21. newact->setStatusTip("Open a new file");
    22. connect(newact,SIGNAL(triggered()),this,SLOT(openfile()));
    23. }
    24. void widget::createStatusBar()
    25. {
    26. statusBar()->showMessage(tr("Ready"));
    27. }
    28. void widget::openfile()
    29. {
    30. QString fileName = QFileDialog::getOpenFileName(this,
    31. tr("Open File"), QDir::currentPath());
    32. }
    To copy to clipboard, switch view to plain text mode 
    when I press the action Open, it does not open a QFileDialog
    Last edited by wysota; 27th September 2014 at 21:05. Reason: reformatted to look better

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: I want to open a QFileDialog, but this code does not open it.

    Is "openfile" declared as SLOT ? Does your class have a Q_OBJECT macro ?

  3. #3
    Join Date
    Jul 2014
    Posts
    95
    Thanks
    67

    Default Re: I want to open a QFileDialog, but this code does not open it.

    thank you very much.I had forgotten the Q_OBJECT.!!! I used the Q_OBJECT and now,it opens the QFileDialog.

Similar Threads

  1. QFileDialog create or open existing directory
    By hypnotic401 in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2012, 17:19
  2. Replies: 2
    Last Post: 28th November 2011, 15:12
  3. the open source flash code for qt?
    By wter27 in forum Qt Programming
    Replies: 3
    Last Post: 8th November 2011, 04:13
  4. Replies: 2
    Last Post: 10th May 2011, 23:03
  5. QFileDialog to stderr: Couldn't open named pipe (2)
    By Ballig in forum Qt Programming
    Replies: 0
    Last Post: 17th January 2010, 13:30

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.