QTextEdit doesn´t display text



  • Hi.
    I´m new to QT and have a big problem with the following code:

    @
    class ComTest : public QWidget, public Ui_ComTestClass
    {
    Q_OBJECT

    public:
    ComTest(QWidget *parent = 0);
    ~ComTest();

    void report(QString txt) { textEdit_show->append(txt); }
    };

    @

    This function (void report(QString txt)) works if I call it from inside the class, but it doesn´t display any text if I call it from a .cpp file outside that class.
    The text submitted is correct, a QMessageBox with that txt is working.

    Can anyone help me?



  • Hi!

    Is the code in your .cpp like:
    @
    void ComTest::report(QString txt)
    {
    textEdit_show->append(txt);
    }
    @

    Could you provide a little more source code if upper code doesn't work.
    I can't find a problem in provided code.



  • My .cpp :

    @
    #include <comtest.h>

    static ComTest *comwin=0;
    static QString msg="";

    int send(char *cmd)
    {
    if(com_isopen==false)
    {
    info_error("COM port is not open");
    return -1;
    }
    if (comwin == 0) comwin = new ComTest();

        if(comwin)
    

    {
    msg="----------------------------\nCommand: ";
    msg+=cmd;
    msg+="\n";
    comwin->report(msg);
    }
    }
    @



  • Did you try step by step with debuger?
    Everything look OK.
    Did you try using non static variable? Just to see if compiler is messing up with you.
    It works normally on my simple test project.

    And it's recommended to use " for your includes. Just a notice.



  • I don´t know how to use the debugger correctly.
    My compiler is VS2008, there I can only see Assembler Code and this is too high for me ;)
    And when I put steps into the code it doesn´t seem to stop on that position.

    Yes, I tried to use a non static variable.
    It even doesn´t work if I call "comwin->report("hello");"
    But a QMessageBox is working with the submitted text, so it should be OK until the function in the class is executed.

    And the strange thing is, that I can use the method in the class from a public slot. If I for example push a button I can display text in the Textedit. There everything is working correctly.



  • In MS VS debuger is probably the simplest thing to use ;) . Add breakpoints, press F5 to start debuging. From there you can then go by step, view variables ( right click on a variable and Quick Watch) etc... But there is an quite good replacement for a debuger. Instead of breakpoints just add qDebug() messages or messages boxes with some text to indicate which code is executed :) .
    Oh Assembler...

    Did you try to clean and recompile your project? Or compiling your project with provided mingw compiler in Qt SDK ( if possible), or with later version of VS compiler, 2010?
    I'm starting to run out of ideas if none of the above will work.



  • Thank you, I will try another compiler later.

    I tried debugging on a release-version...
    That was the reason I could only see the assembler code :D

    In debug-mode I can see the variables and stop the program at the report-function.

    Thanks for your help, if I find a solution I will tell you.



  • I found the problem.
    I created two objects of the class ComTest and did not display the second object with show() or exec(). So the report-function was called but displayed on the wrong object.

    Beginner-fault :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.