Re: QTextEdit -> add Text
Are there any extra threads involved? Could you run the application via debugger and paste backtrace?
Re: QTextEdit -> add Text
Hello JPN,
thanks for the fast reply
basicly i have no idea howto debug that.
the function openFileDialog() is posted as it is in my code.
Could you provide my howto debug & backtrace on a Windows host.
I am using Qt4.3.2 on Windows Vista
My IDE of choice right now is HaiQ
edit: if i use the clear() function which results in the app crashing Windows Debug information is as follows:
Code:
Problemsignatur:
Problemeventname: APPCRASH
Applicationname: myexename.exe
Applicationversion: 0.0.0.0
ApplicationTimestamp: 47679bb6
Erroromodulename: QtGui4.dll
Errormodulversion: 4.3.2.0
Errormodultimestamp: 4701090f
ExceptionCode: c0000005
Exceptionoffset: 004a24f9
OS Version: 6.0.6000.2.0.0.256.6
.....
Re: QTextEdit -> add Text
Try downloading and installing GDB for MinGW. Compile your application in debug mode (you should also have debug version of Qt installed):
Quote:
make clean
qmake -config debug
make
Then, launch the application via gdb, run the app, make it crash, show the backtrace:
Quote:
gdb myapp.exe
(gdb) run
...
Program received signal SIGSEGV, Segmentation fault.
...
(gdb) bt
Re: QTextEdit -> add Text
ok gonna try that.
so basicly both ideas:
// Now we want to add an entry into our logging QTextEdit at the Main window)
// this idea results in a crash
loggingBox->setText("open file dialog was selected")
// Trying something diffrent ....just clearing the text inside Logging Box
// this idea results in a crash too
loggingBox->clear();
should work, right ?
Re: QTextEdit -> add Text
Well, let's say it shouldn't crash. Don't expect to see text changing on the fly, though. You will have to let the application to process its events to see changes.
Code:
{
// changing text will schedule a paint event...
textEdit->setText(...);
// ...but the text edit has no chance to update its content before it gets cleared
textEdit->clear();
}
One easy solution is to delay clearing a bit, and return back to the event loop from the slot of yours for a while:
Code:
{
textEdit->setText(...);
// give text edit a chance to update its content before clearing it
QTimer::singleShot(500, textEdit,
SLOT(clear
()));
}
Re: QTextEdit -> add Text
Hi again
ok basicly i did a small mistake while explaning my code:
Those 2 lines where just examples:
---
textEdit->setText(...);
textEdit->clear();
---
that means: i havent tried to use them both at once....
Only each-cmd as single command.
And in both cases the application does crash.
Thats why i was wondering whats wrong about my code in general.
At the moment i am switching my environment (to Ecplise etc...) and
gonna try a real debug then. Lets see if it acts similar in the new env.
best regards and thank you for the input till now
Re: QTextEdit -> add Text
Where do you instantiate that text edit?
I think it might be uninitialized.
Re: QTextEdit -> add Text
Hello Marcel
inside my mainwindow.cpp i have the following
Code:
// Logging
loggingBox->setText( "* Application started.\n* Logging enabled.\n" );
loggingBox->setMinimumSize(490, 50);
loggingBox->setMaximumSize(490, 50);
loggingBox->setBaseSize(490,50);
loggingBox->setReadOnly(false);
loggingBox
->setToolTip
(QString::fromUtf8("This window shows all log-entries."));
The Box is displays at application launch, displays the predefined text and i guess it is implemented as supposed (ok as a beginner i am never 100% sure)
Edit: And that was the mistake hehe
It works like that:
Code:
// Logging
loggingBox->setText( "* Application started.\n* Logging enabled.\n" );
loggingBox->setMinimumSize(490, 50);
loggingBox->setMaximumSize(490, 50);
loggingBox->setBaseSize(490,50);
loggingBox->setReadOnly(false);
loggingBox
->setToolTip
(QString::fromUtf8("This window shows all log-entries."));
Ok to get it finaly working as supposed i need to do a last change i case (regarding that specific point)
At the moment i am just replacing the text of my logging box if the function is called like that:
Code:
loggingBox->setText("new text");
Basicly i want to add the new text to the existing one
Is there something like addText or similar or how can i solve that issue in a better way ?
Re: QTextEdit -> add Text
Good that the problem solved, but I still suggest learning how to get a backtrace out of a debugger. You would have seen yourself from the backtrace that QTextEdit::setText() or QTextEdit::clear() was called via null/uninitialized pointer. ;)
Re: QTextEdit -> add Text
Yeah, I was just gonna say that. You created the text box somewhere in a function, locally and got destroyed.
For appending text: QTextEdit::append()
Re: QTextEdit -> add Text
hi again
yes, a working debugger makes sense for sure.
unfortunaly i messed half of my day with setting up Eclipse, Qt, MinGW etc and finaly switched back to my old setup as eclipse looked kinda special regarding the setup.
Maybe i should start tomorrow again searching for a good howto setup Eclipse, MinGw, Qt for full debug mode.
Next problem is: i am working as default windows user, which means i have to re-edit all right etc..... Not the best situation.
Regarding my loggingBox:
Any final idea howto add the text to the existing one ? as using setText just replaces the text.
best regards
ape
Finally: big big thanks for you 2 guys. I can imagine it is hard to help starting-users like me if you know the language yourself fora long time.
Hopefully i will not ask too much in the near future.
Re: QTextEdit -> add Text
Quote:
Originally Posted by
ape
Regarding my loggingBox:
Any final idea howto add the text to the existing one ? as using setText just replaces the text.
Search QTextEdit docs for "append". :)
Re: QTextEdit -> add Text
regarding append:
i already noticed the hint above...guess we were all answering & asking at the same time.....ended up in a bit messed up thread. Sorry about that.
Ok one final question regarding my QTextEdit:
I remember during my first test with QTextEdit the box displayed a scrollbar if it was needed.
I "think" i havent added this function
(to add a scrollbar if amount lof lines > amount of visible lines in the QTextEdit) myself.
Actually as i am now able to insert Text into that box i am realizing that i dont have that anymore.
So the question:
Is it the default behaviour, that a scrollbar appears ? or do i have to define that manually ?
at the moment i define just the following
Code:
// Logging
loggingBox->setText( "* Application started.\n* Logging enabled." );
loggingBox->setMinimumSize(490, 50);
loggingBox->setMaximumSize(490, 50);
loggingBox->setBaseSize(490,50);
loggingBox->setReadOnly(true);
loggingBox
->setToolTip
(QString::fromUtf8("This window shows all log-entries."));
A quick yes/no should be enough, as i have to train my using qt-docs skill :D
Best regards
ape
Re: QTextEdit -> add Text
Yes, a scroll bar should appear by default as needed.
PS. You can extremely easily verify it with only a few lines of code:
Code:
// main.cpp
#include <QtGui>
int main(int argc, char* argv[])
{
t.show();
return a.exec();
}
Then just type in the magic combo
Quote:
qmake -project
qmake
make
./app
...and start typing to see whether a scroll bar appears. In the end it will take less time to test such things than to post a question on the forums. ;)
Re: QTextEdit -> add Text
true :D
But then again i am asking myself, why my current QTextEdit no longer displays its scrollbars.
Could that be related with my layout and my defined size of the object itself ?
EDIT: solved
i have to damn myself. Actually i am working with a fix window size (which was changed lately) and the QTextEdit had a fix sized too....which i forgot to change too during that resizing action in my source.
guess best thing is not to work with fixed sizes, if i am not forced too.
Thanks again to all helping people inhere.
Re: QTextEdit -> add Text
Quote:
Originally Posted by
ape
guess best thing is not to work with fixed sizes, if i am not forced too.
Definitely. Not everyone has same resolution. A fixed size of a window/control might be completely inappropriate for somebody else. Fixed sizes will also make localization unnecessarily hard. Imagine that same widget should have different textual content depending on the chosen language. Very easy with flexible layouts, a pain with fixed sizes.
Quote:
Thanks again to all helping people inhere.
You're welcome. :)