Why console prompt: QEventLoop: Cannot be used without QApplication?
-
Hi and welcome to devnet,
Can you show the code you are using ?
-
@SGaist
The code is as follows:# include < QApplication > # include < QSettings > # include < qfile. H > # include "tool/enum. H" # include < dialog/dlg_reg. H > # include "dialog/dlg_login. H" # include "window_main. H" Int main(int argc, char *argv[]) { QApplication app (arg c, argv); QFile file (" : / QSS/white QSS "); The file open (QFile: : ReadOnly); QString styleSheet = QLatin1String (file. ReadAll ()); App. SetStyleSheet (styleSheet); }
I follow these steps:
Build-> Clean Project 'XYZ'
The Build - > Run qmake
Build-> Build Project 'XYZ'
It still says:
QEventLoop: Cannot be used without QApplication[EDIT: Added code formatting around source code --JKSH]
-
@canid said in Why console prompt: QEventLoop: Cannot be used without QApplication?:
# include < QApplication > # include < QSettings > # include < qfile. H > # include "tool/enum. H" # include < dialog/dlg_reg. H > # include "dialog/dlg_login. H" # include "window_main. H" Int main(int argc, char *argv[]) { QApplication app (arg c, argv); QFile file (" : / QSS/white QSS "); The file open (QFile: : ReadOnly); QString styleSheet = QLatin1String (file. ReadAll ()); App. SetStyleSheet (styleSheet); }
This code cannot compile. Please copy + paste the actual code from your project.
Also, show the code for your enum, dialog, and window.
-
@canid That really doesn't mean that your question can be answered without source code. In this case there already was a suggestion what to check: "global QObject variable somewhere" - did you check? If not then please do. If you want others to check that then please post your source code the only other thing others can do is guessing...
-
@canid I don't know who downvoted your posts, I did not. I only downvote posts where the poster behaves rude.
But you should be aware that asking for help for programming issues/questions and then saying that code is actually not necessary because somewhere else questions were answered without code isn't a good idea. Sometimes you can answer a question without code, but sometimes you can only guess what could be wrong (as it was already the case here with the global QObject, did you check by the way? I'm asking this question second time now) if you cannot see the actual code. And actually you will see allot of code in topics here and you will see that others often ask for code, nothing special, really. Programming errors are done in code, so code is often essential to find an issue.
And why do you refuse to post the code? Is it secret? -
@canid said in Why console prompt: QEventLoop: Cannot be used without QApplication?:
@jsulm
Please give an example to show that not uploading source code does not solve the problem.this thread.
I have posted the main function code, how can you say there is no code
let me quote @JKSH
This code cannot compile. Please copy + paste the actual code from your project.
Also, show the code for your enum, dialog, and window -
@canid said in Why console prompt: QEventLoop: Cannot be used without QApplication?:
Please give an example to show that not uploading source code does not solve the problem
Sorry, but I will not, you can search by yourself if you don't believe me (I am in this forum since many years already, so I'm speaking from my own experience, based on what do you make your claims?). I really wonder why you think that programming issues can always be solved without checking source code (not much experience in software development I guess?)? What do you expect from other people here? That they use a crystal ball or some other magic to find out where in your code the issue is?
"main function code" - there is more code in your project...
"how can you say there is no code" - I did not, I and others are asking you to post more of your code not just main.
I will ask for the third (and last time): did you check whether there is any global/static QObject somewhere in your code?
-
@canid Your refusal to provide your code, so others can look into it to find the issue, doesn't help either.
As you apparently don't want to simply post your code instead of making an endless and useless discussion I will retract from this thread... -
@canid said in Why console prompt: QEventLoop: Cannot be used without QApplication?:
Please give an example to show that not uploading source code does not solve the problem.
- https://forum.qt.io/topic/72184/hide-show-a-widget/
- https://forum.qt.io/topic/94199/letting-the-user-set-the-respective-directory-within-a-qt-wigdet-application
- https://forum.qt.io/topic/104087/text-alignment
After the asker provided code, the helper was able to see the problem in the code immediately. Thus, a solution was found very quickly.
Pay extra attention to the "Text Alignment" example: Because the asker provided code in the original post, the helper was able to post the solution in the very first reply!
I have posted the main function code
Thank you for that. However, we still need more because the code that you posted cannot produce the "QEventLoop: Cannot be used without QApplication" message.
That's why I said: Please copy + paste the actual code from your project. Then, we will be able to show you where to fix the problem.
Note: We're not asking for code for fun. We're asking for code because the code will help us to help you.