Results 1 to 15 of 15

Thread: I don't get expected output in text browser

  1. #1
    Join Date
    Jul 2010
    Posts
    71
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Red face I don't get expected output in text browser

    There is a problem in the program

    in mainwindow.h
    Qt Code:
    1. class input_events //: public MainWindow
    2. {
    3. typedef struct input ie;
    4.  
    5. public:
    6. ie *l;
    7. ~input_events();
    8. input_events();
    9. void add_ie(ie *p);
    10. };
    To copy to clipboard, switch view to plain text mode 

    in mainwindow.cpp

    Qt Code:
    1. struct input
    2. {
    3. int id;
    4. struct input * suiv;
    5. };
    6. typedef struct input ie;
    To copy to clipboard, switch view to plain text mode 

    And also
    Qt Code:
    1. void MainWindow::print()
    2. {
    3. input_events * ptr_ie;
    4. ie * ine;
    5.  
    6. QString resultString = "";
    7. for(ine=ptr_ie->l; ine; ine = ine->suiv)
    8. {
    9. ui->textBrowser->setText(ui->textBrowser->toPlainText() + resultString.setNum(ine->id) + " ");
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    The problem is that does not print output in function print()

    the program here <link to 3rd party site removed, use attachments instead>

    Thank you for your time
    Last edited by NewLegend; 24th July 2010 at 21:40.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Excuse me a minute

    Please edit your post and write like a normal person or I will simply delete this thread And change this ridiculous thread title. You have violated at least two rules of this forum and also a few netiquette ones.

    Edit: some people just don't learn...
    Last edited by wysota; 24th July 2010 at 21:29.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2010
    Posts
    71
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Excuse me a minute

    Thank you for this observation
    But I want a solution

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Excuse me a minute

    Quote Originally Posted by NewLegend View Post
    But I want a solution
    And I normal user who also don't send two(!) private messages with the same content as this thred.

    Seems we both don't get what we want!

  5. #5
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Excuse me a minute

    Your loop header (and quite a few other things) makes no sense at all. Neither do the variables, their initialization and their usage. But as constructed, your loop will simply not run, which would possibly explain why nothing gets printed.

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: I don't get expected output in text browser

    It will even crash at
    Qt Code:
    1. for(ine=ptr_ie->l; ine; ine = ine->suiv)
    To copy to clipboard, switch view to plain text mode 
    since ptr_ie is not initialised.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Excuse me a minute

    I would ask a different question - how come doesn't it crash on the first try of dereferencing ptr_ie. It probably manages to return 0 by accident gracefully exiting the loop but it's still an interesting question...

    Edit: Gosh... beaten to it
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Excuse me a minute

    Seems like the code just depends on the (undefined) contents of the stack. Alter the code a little and it'll crash in a perfectly normal fashion.

    I also don't see how it's even Qt related, never mind "more advanced Qt" related.

  9. #9
    Join Date
    Jul 2010
    Posts
    71
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Excuse me a minute

    I Declare input_events * ptr_ie as a private member in Mainwindow class and remove ptr_ie declarations from your get_info and print function.
    But
    Does not print all of the contents linked list

    See
    Qt Code:
    1. class input_events
    2. {
    3. typedef struct input ie;
    4.  
    5. public:
    6. ie *l;
    7. ~input_events();
    8. input_events();
    9. void add_ie(ie *p);
    10. void gener_ie();
    11. friend class Trajectoire;
    12. };
    To copy to clipboard, switch view to plain text mode 

    And

    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit MainWindow(QWidget *parent = 0);
    7. ~MainWindow();
    8. Ui::MainWindow *ui;
    9.  
    10. private slots:
    11. void GetInfo();
    12. void print();
    13.  
    14. private:
    15. input_events * ptr_ie;
    16.  
    17. };
    To copy to clipboard, switch view to plain text mode 
    ^^^^^^^^^^^^^^^^^^^^^^^
    See private



    And this a function
    Qt Code:
    1. void MainWindow::print()
    2. {
    3. //input_events * ptr_ie;
    4. ie * ine;
    5.  
    6.  
    7. for(ine=ptr_ie->l; ine; ine = ine->suiv)
    8. {
    9. QString resultString = "";
    10. ui->textBrowser->setText( ui->textBrowser->toPlainText() + resultString.setNum(ine->id) + " ");
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    The problem is that does not print ALL linked list
    Last edited by wysota; 24th July 2010 at 23:34.

  10. #10
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Excuse me a minute

    You never increment your loop variable, and the loop will never terminate with the existing check.

    Why are you implementing your own linked list class? It is very easy to get such an implementation wrong, especially when you try to be tricky, and there's a perfectly good linked list class already available through std::list<>, and likely through Qt itself.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Excuse me a minute

    Quote Originally Posted by NewLegend View Post
    The problem is that does not print ALL linked list
    What does it print?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Jul 2010
    Posts
    71
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Excuse me a minute

    Quote Originally Posted by wysota View Post
    What does it print?
    set of ID .....

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Excuse me a minute

    Quote Originally Posted by NewLegend View Post
    set of ID .....
    Well... that's what your code does - concatenates numbers. What did you expect to receive?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14
    Join Date
    Jul 2010
    Posts
    71
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Excuse me a minute

    see the Attachments

    I add set of Id
    then print All this Id
    Attached Files Attached Files

  15. #15
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Excuse me a minute

    Post what you expect to get (actual output) and then post what you are actually getting (actual output).

    It is also rather odd that you don't use the pre-existing templates for this kind of code to make it easier for yourself.

Similar Threads

  1. Replies: 6
    Last Post: 28th January 2014, 11:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.