Results 1 to 7 of 7

Thread: Choosing between UI on start up.

  1. #1
    Join Date
    Jul 2013
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Choosing between UI on start up.

    Hello, I've encountered an error for when I want my application to do one of two things.


    Normally when you create a QT application it starts the main window, well I've added the code

    Qt Code:
    1. std::ifstream ifile("C:/Program Files/Skittles/Install.cab");
    2. if (ifile.good() == true)
    To copy to clipboard, switch view to plain text mode 

    Depending on the true or false status it runs a different UI.

    However I right click on Project Name > Add New > QT - QT designer form class > Dialog with buttons bottom.


    Now this code here
    Qt Code:
    1. else if (ifile.good() == false)
    2. {
    3. install MyInstall;
    4. MyInstall.setModal(true);
    5. MyInstall.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 

    Should open up the new UI since I named it install, I've included it's header file. But when I run it, a few things happen, 1: It will sucsessfully open 2: It will open for me but for a friend on Windows 8 it will not. 3: It gives a run time error http://gyazo.com/54b533dc8c40edbe837ad858eb6fdf3e 4: It says in the debug log "QWidget: Must construct a QApplication before a QPaintDevice"

    To the extent I know this is all I have done to make this project and I am truly stuck on what to do or how to get it working. So any and all help would be greatly appreacted.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Choosing between UI on start up.

    Can you post the rest of your main.cpp?

    Cheers,
    _

  3. #3
    Join Date
    Jul 2013
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Choosing between UI on start up.

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "install.h"
    3. #include <QApplication>
    4. #include <fstream>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. std::ifstream ifile("C:/Program Files/Skittles/Install.cab");
    9. if (ifile.good() == true)
    10. {
    11. QApplication a(argc, argv);
    12. MainWindow w;
    13. w.show();
    14. return a.exec();
    15. }
    16. else if (ifile.good() == false)
    17. {
    18. install MyInstall;
    19. MyInstall.exec();
    20. }
    21. return 0;
    22. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Choosing between UI on start up.

    2 & 3) You have probably not deployed all the necessary components to support your application to your friend's Windows 8 machine (it could be XP, Vista or 7 with the same result).

    4) Line 18/19 will complain because you have not constructed a QApplication before calling code that tries to paint. This is exactly what the error message is telling you.

  5. #5
    Join Date
    Jul 2013
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Choosing between UI on start up.

    Quote Originally Posted by ChrisW67 View Post
    2 & 3) You have probably not deployed all the necessary components to support your application to your friend's Windows 8 machine (it could be XP, Vista or 7 with the same result).

    4) Line 18/19 will complain because you have not constructed a QApplication before calling code that tries to paint. This is exactly what the error message is telling you.
    I've made sure all the files that I know of are in the same directory. Also, would you be able to explain how to construct a QApplication since I haven't learnt that far into QT yet. I'm only up to: this video in a QT tutorial series. I follow what he does and it doesn't work, granted he makes it so the user has to click a button. Which I am thinking that could be actually easier.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Choosing between UI on start up.

    If you have put "all the files I know" in the one directory then you almost certainly have not deployed the application correctly. There is a directory structure required and it is documented in the Deploying an Application on Windows : Creating the Application Package docs matching your Qt4 or Qt5 version.

    Constructing an object has nothing to do with Qt, it is basic C++ knowledge, as is the scope of variables. Line 11 of your main.cpp constructs a QApplication object called "a" with a limited scope. That QApplication object does not exist if lines 18-19 are being executed. Either construct the QApplication object once at the top of main() or before line 18.

    Video tutorials are nice but you should at least read the Getting Started Programming with Qt and associated tutorial material in the docs that come with Qt.

  7. #7
    Join Date
    Jul 2013
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Choosing between UI on start up.

    Quote Originally Posted by ChrisW67 View Post
    If you have put "all the files I know" in the one directory then you almost certainly have not deployed the application correctly. There is a directory structure required and it is documented in the Deploying an Application on Windows : Creating the Application Package docs matching your Qt4 or Qt5 version.

    Constructing an object has nothing to do with Qt, it is basic C++ knowledge, as is the scope of variables. Line 11 of your main.cpp constructs a QApplication object called "a" with a limited scope. That QApplication object does not exist if lines 18-19 are being executed. Either construct the QApplication object once at the top of main() or before line 18.

    Video tutorials are nice but you should at least read the Getting Started Programming with Qt and associated tutorial material in the docs that come with Qt.
    Thanks for all the help, I guess I got a week free I'll do all the reading and watching so I can atleast gain more knowledge about QT.

    So thanks for the help and proving this is a good community, hopefully when I learn more about QT I can come and help people with problems.

Similar Threads

  1. Replies: 1
    Last Post: 15th May 2011, 10:11
  2. [GUI Thread]: Choosing it ! How to ?
    By didier in forum Qt Programming
    Replies: 4
    Last Post: 15th October 2010, 09:03
  3. Help choosing a model type for QTableView
    By goes2bob in forum Newbie
    Replies: 1
    Last Post: 10th March 2008, 02:22
  4. Choosing a qt4 book
    By asieriko in forum General Discussion
    Replies: 14
    Last Post: 7th October 2007, 14:31
  5. Replies: 2
    Last Post: 19th April 2006, 19:11

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.