sometimes qt was ended forcefully, weird.
-
@SGaist
thanks, the gui is supposed to be fullscreen all the time,and some initialization work should be done only once, as well as the layout work which is based on fullscreen.anyway, i just found the problem of ui->statusbar line might be related to stylesheet. the original stylesheet set in the property window is as below,
QStatusBar{border-top: 1px outset grey;}
QStatusBar::item{border: 0px}
if i clear this setting, it seems it's not reporting the error(trying to Trying to construct an instance of an invalid type) anymore.
if i change the stylesheet to some back-ground color, it might be crash again, but not with the error (trying to Trying to construct an instance of an invalid type) anymore.
even i set the stylesheet in the mainwidow.cpp code, it also might be crashed sometimes.actually, i still don't believe it's the root reason, one reason is i don't see anything is wrong with the stylesheet, the other reason it never crash in the old backup version.
i googled a lot but i haven't found anything helpful.
i have stuck into here for a long time, based on the information i just mentioned, do you have any further advice?
thank you all very much for your time and help.
-
@circle are you sure you set
bOnlyOnce
to false anywhere ? It's not in your code.resize events may be queued up already, when its first called, and QmessageBox will spin its own event loop that could be the problem here
@J-Hilk
sorry forget to post that line, the first thing in the if(bOnlyOnce) block is to set bOnlyOnce = false;i understand resize events may be queued, and QMessageBox has its own event loop, but sorry i am not very aware of what you said, how it affect?
from my debug log, it will go to the resize function block after showFullscreen() in the constructor, but it's not visible yet, so after back to the constructor, the system will call resize function again to do the initialization work.
In addition, when i press F5 to debug the program, i never reproduce the problem. and i can't reproduce the problem with the old backup version, and they are same in the constructor and resize function block.
-
Can you explain what kind of logic is required to be run in the resize event ?
Typically I do not see why you would need to add a widget there.
-
Can you explain what kind of logic is required to be run in the resize event ?
Typically I do not see why you would need to add a widget there.
@SGaist
thanks for your time. my app is fullscreen always, and the main reason i do the initialization work in the resize event is, i need to know the size of the fullscreen, as a lot of drawing is based on this size. Most of the drawing is done in the memory, while the small part is done in paintEvent.
where do you think i should do these things? showEvent? -
@SGaist
thanks for your time. my app is fullscreen always, and the main reason i do the initialization work in the resize event is, i need to know the size of the fullscreen, as a lot of drawing is based on this size. Most of the drawing is done in the memory, while the small part is done in paintEvent.
where do you think i should do these things? showEvent?@circle said in sometimes qt was ended forcefully, weird.:
where do you think i should do these things?
You can get the size (
geometry
) of your widget anywhere, without calling the stuff every time you resize.If you want to do something just once, consider doing it inside your c'tor or use the showEvent, when you need the actual size.
(Your widget's size in c'tor and showEvent will / may be different, because of layouts) -
@circle said in sometimes qt was ended forcefully, weird.:
where do you think i should do these things?
You can get the size (
geometry
) of your widget anywhere, without calling the stuff every time you resize.If you want to do something just once, consider doing it inside your c'tor or use the showEvent, when you need the actual size.
(Your widget's size in c'tor and showEvent will / may be different, because of layouts) -
@circle said in sometimes qt was ended forcefully, weird.:
tried to get the real fullscreen's size in the c'tor
QScreen doesn't work differently if it is called in the ctor or anywhere else.
-
Depending on what you need, I would rather go with changeEvent and check the
QEvent::WindowStateChange
event. You will know there when the window is fullscreen.But again, doing stuff that depends on the specifics of being fullscreen is a bit surprising. Painting is usually done so that it does not directly depend on one specific size because even if fullscreen you may have different sizes.
-
@circle said in sometimes qt was ended forcefully, weird.:
tried to get the real fullscreen's size in the c'tor
QScreen doesn't work differently if it is called in the ctor or anywhere else.
@Christian-Ehrlicher
more precisely, what i need is the size of centralwidget when it's fullscreen. so i just use the width() and hegith() to obtain those when it's fullscreen.
i didn't use QScreen, should i?@SGaist
there may be different ways to get the size, but i still don't have a clue why it produce such an error. it seems have nothing to do with the error, and why sometimes it's working, sometimes not. -
@circle said in sometimes qt was ended forcefully, weird.:
i didn't use QScreen, should i?
I suggest you to use it so I would say it's worth a try reading the documentation, isn't it?
-
@Christian-Ehrlicher
more precisely, what i need is the size of centralwidget when it's fullscreen. so i just use the width() and hegith() to obtain those when it's fullscreen.
i didn't use QScreen, should i?@SGaist
there may be different ways to get the size, but i still don't have a clue why it produce such an error. it seems have nothing to do with the error, and why sometimes it's working, sometimes not.@circle said in sometimes qt was ended forcefully, weird.:
more precisely, what i need is the size of centralwidget when it's fullscreen.
Then it doesn't sound like you should be looking at
QScreen
at all.thanks, i tried to get the real fullscreen's size in the c'tor or in the showEvent,
To get a size of widget (not the full screen, which you shouldn't be interested in) correctly it needs to be shown. If you call it too early, you get rubbish. Constructor is not the place. If in a
showEvent()
, IIRC you should call the baseshowEvent()
before you try to read the size. -
@circle said in sometimes qt was ended forcefully, weird.:
more precisely, what i need is the size of centralwidget when it's fullscreen.
Then it doesn't sound like you should be looking at
QScreen
at all.thanks, i tried to get the real fullscreen's size in the c'tor or in the showEvent,
To get a size of widget (not the full screen, which you shouldn't be interested in) correctly it needs to be shown. If you call it too early, you get rubbish. Constructor is not the place. If in a
showEvent()
, IIRC you should call the baseshowEvent()
before you try to read the size. -
@circle said in sometimes qt was ended forcefully, weird.:
i still can't read the right size of the centralwidget.
Again: use QScreen to determine the screen size!
-
@circle said in sometimes qt was ended forcefully, weird.:
i still can't read the right size of the centralwidget.
Again: use QScreen to determine the screen size!
@Christian-Ehrlicher
How will knowing the screen size help this user if he want to know the central widget size? -
@JonB said in sometimes qt was ended forcefully, weird.:
if he want to know the central widget size?
my app is fullscreen always
so...
-
@JonB said in sometimes qt was ended forcefully, weird.:
if he want to know the central widget size?
my app is fullscreen always
so...
@Christian-Ehrlicher
So? :) The central widget is some widget in the full screen app, but there can be all sorts round the edges. So the widget itself won't be the full screen. I'm thinking like the central widget area in aQMainWindow
. I guess you're not? -
@JonB said in sometimes qt was ended forcefully, weird.:
I guess you're not?
I don't see a need for all the calculation at all - using a proper layout will make all those stuff superfluous.
-
@JonB said in sometimes qt was ended forcefully, weird.:
I guess you're not?
I don't see a need for all the calculation at all - using a proper layout will make all those stuff superfluous.
@Christian-Ehrlicher said in sometimes qt was ended forcefully, weird.:
I don't see a need for all the calculation at all - using a proper layout will make all those stuff superfluous.
I agree! But it wasn't the question :)
-
@all,
thank you so much for your time. sorry i wasn't clear about my requirement. what i care is the centrawidget size when QMainWindow is in fullscreen.again, i am posting the code with the erros,
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); showFullScreen(); ui->dockWidget->setWidget(ui->tableWidget); ui->line1->hide(); } void MainWindow::resizeEvent(QResizeEvent *event) { QMainWindow::resizeEvent(event); // Your code here. static bool bOnlyOnce = true; if (bOnlyOnce && isVisible()) { bOnlyOnce = false; memory allocation, file reading and data initialization QFileInfo fileInfo(QCoreApplication::applicationFilePath()); if () QMessageBox::information(this, "title", QString("%1").arg(fileInfo.size())); //***sometimes crash here ??? get the size of centralwidget, prepare drawing environment ui->statusbar->addWidget(ui->lable1, 40); //***sometimes it crash here if i comment out QMessageBox line above*** ??? } }
now the QMessageBox line would crash sometimes(qtcreator says the process was ended forcefully), and if i comment out this line, the ui->statusbar line sometimes would report "Trying to construct an instance of an invalid type, type id: 1061" and the process was ended forcefully.
i haven't found any rules about "sometimes", sometimes it will crash several times continuously when i press CTRL+R, but sometimes the program works fine.
And it's working alwasys fine if i press F5 to debug the app.In addition, in the old backup version, it's working always fine. this version just has more functions after the crash point.
-
As @J-Hilk already told you 4 days ago - don't create an eventloop in a resize event!