PDA

View Full Version : I don't get expected output in text browser



NewLegend
24th July 2010, 16:20
There is a problem in the program

in mainwindow.h

class input_events //: public MainWindow
{
typedef struct input ie;

public:
ie *l;
~input_events();
input_events();
void add_ie(ie *p);
};

in mainwindow.cpp


struct input
{
int id;
struct input * suiv;
};
typedef struct input ie;

And also

void MainWindow::print()
{
input_events * ptr_ie;
ie * ine;

QString resultString = "";
for(ine=ptr_ie->l; ine; ine = ine->suiv)
{
ui->textBrowser->setText(ui->textBrowser->toPlainText() + resultString.setNum(ine->id) + " ");
}
}

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

wysota
24th July 2010, 19:08
Please edit your post and write like a normal person or I will simply delete this thread :mad: 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...

NewLegend
24th July 2010, 21:42
Thank you for this observation
But I want a solution

Lykurg
24th July 2010, 21:45
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!

SixDegrees
24th July 2010, 21:47
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.

tbscope
24th July 2010, 22:00
It will even crash at

for(ine=ptr_ie->l; ine; ine = ine->suiv)
since ptr_ie is not initialised.

wysota
24th July 2010, 22:01
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 :)

squidge
24th July 2010, 22:38
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.

NewLegend
24th July 2010, 22:51
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


class input_events
{
typedef struct input ie;

public:
ie *l;
~input_events();
input_events();
void add_ie(ie *p);
void gener_ie();
friend class Trajectoire;
};

And


class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
Ui::MainWindow *ui;

private slots:
void GetInfo();
void print();

private:
input_events * ptr_ie;

};
^^^^^^^^^^^^^^^^^^^^^^^
See private



And this a function

void MainWindow::print()
{
//input_events * ptr_ie;
ie * ine;


for(ine=ptr_ie->l; ine; ine = ine->suiv)
{
QString resultString = "";
ui->textBrowser->setText( ui->textBrowser->toPlainText() + resultString.setNum(ine->id) + " ");
}
}

The problem is that does not print ALL linked list

SixDegrees
24th July 2010, 23:09
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.

wysota
24th July 2010, 23:30
The problem is that does not print ALL linked list
What does it print?

NewLegend
25th July 2010, 01:50
What does it print?

set of ID .....

wysota
25th July 2010, 01:55
set of ID .....

Well... that's what your code does - concatenates numbers. What did you expect to receive?

NewLegend
25th July 2010, 02:07
see the Attachments

I add set of Id
then print All this Id

squidge
25th July 2010, 09:21
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.