PDA

View Full Version : Choosing between UI on start up.



WhackaCrack
2nd July 2013, 13:55
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


std::ifstream ifile("C:/Program Files/Skittles/Install.cab");
if (ifile.good() == true)

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

else if (ifile.good() == false)
{
install MyInstall;
MyInstall.setModal(true);
MyInstall.exec();
}

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.

anda_skoa
2nd July 2013, 14:16
Can you post the rest of your main.cpp?

Cheers,
_

WhackaCrack
2nd July 2013, 14:23
#include "mainwindow.h"
#include "install.h"
#include <QApplication>
#include <fstream>

int main(int argc, char *argv[])
{
std::ifstream ifile("C:/Program Files/Skittles/Install.cab");
if (ifile.good() == true)
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
else if (ifile.good() == false)
{
install MyInstall;
MyInstall.exec();
}
return 0;
}

ChrisW67
2nd July 2013, 23:20
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.

WhackaCrack
3rd July 2013, 03:12
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 (http://www.youtube.com/watch?v=wUH_gu2HdQE) 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.

ChrisW67
3rd July 2013, 06:39
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 (http://qt-project.org/doc/qt-4.8/deployment-windows.html#creating-the-application-package) or Qt5 (http://qt-project.org/doc/qt-5.0/qtdoc/deployment-windows.html#creating-the-application-package) 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.

WhackaCrack
3rd July 2013, 07:05
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 (http://qt-project.org/doc/qt-4.8/deployment-windows.html#creating-the-application-package) or Qt5 (http://qt-project.org/doc/qt-5.0/qtdoc/deployment-windows.html#creating-the-application-package) 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.