PDA

View Full Version : Display Problem



yuvaraj.yadav
1st May 2009, 12:17
Hi


I added the frame within list view.......


It is showing the of sutput fraction oeconds and closed the window automatically....

I created one frame class called Tweet. There i used to display the image,some text..

In output it showing show only frame,not showed the image,text..... frame also showing fraction of seconds and automatically closed the window.....code
Qt Code:



Tweet *tweet;
setVisible(this)
ui->listView->setIndexWidget(item(0)->index() , tweet );
ui->listView->setUpdatesEnabled( true );

if i change the tweet width to listview width ,it also not changing....


tweet->resize( ui->listView->width() , tweet->height() );

please help me


Thanks

Yuva R

Lykurg
1st May 2009, 12:48
Hey, how often do you need to be told, to don't multiple post an issue? And further please learn the basics of C++!

It is showing nothing because it's an empty pointer! use
Tweet *tweet = new Tweet(); And wasn't you told to better not use QListView? May it is better to use QListWidget.

faldzip
1st May 2009, 17:31
Look here: http://www.cplusplus.com/doc/tutorial/
and here: http://cpp-tutorial.cpp4u.com/

yuvaraj.yadav
2nd May 2009, 05:24
Thanks for your replies....

I am learning the c++.

Here I used the list widget...

I need 20 rows ....

still it is not displaying the my frame within listwidget


Tweet *tweet = new Tweet(this);
for (int i = 0; i < 20; i++ ) {
ui->listWigdet->setIndexWidget(item(i)->index(),tweet);
}



please find my Tweet class code in attachment...

please help me

faldzip
2nd May 2009, 08:35
there is nothing helpful in those files you attached. And they are usind some .ui file which is not attached, and where all the gui is. Can you just attach your files? Files where you want to use that Tweet? For example what the item(int index) function come from?



I am learning the c++.
So learn it a little bit more on some simple examples and then try something more complex. Because we see you have a lack of basic C++ knowledge even with very simple C++ statements, so we can paste some working code for you but you will not understand major part of it! without a proper C++ knowledge...

yuvaraj.yadav
2nd May 2009, 09:28
Thanks for your reply....

I will continue my learning with complex examples of c++.

Here i have attached the files....


please help me

faldzip
2nd May 2009, 10:12
first of all this is quite weird to me (I'd rather use QStandardItemModel as member variable):

class MainWindow : public QMainWindow, QStandardItemModel
but this way it can maybe work too... But:


MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
ui->setupUi(this);
setVisible(true); // 1
qDebug() << " list view";
Tweet *tweet = new Tweet(); // 2
for (int i = 0; i < 24; i++ ) {
tweet->resize( ui->listWidget->width() , tweet->height() );
item(i)->setSizeHint(tweet->size()); // 3
ui->listWidget->setIndexWidget(item(i)->index(),tweet); // 4
}
}

this constructor it's problem in your case. And your problem is not that it's not showing frame, but it's crashing because of segmentation fault!. And segmentation fault is commonly the error caused by bad code - means you can't write it in way it can work (and it is n C and C++, Qt don't do seg faults by itself) - back to the old story - learn some C++...
But ok, I can explain your errors.
In line marked as "// 1" you are calling setVisible(true); it's not an error maube but you are also calling show in main() finction which shows your main window - and that the way it should be, so just delete that line.
In line marked as "// 2" - you created a Tweet, but it's just one Tweet. You want to have 24 same Tweets in list?
Ok, and now you start for loop. Tell me how many items is in your model at the start of the for loop? Don't guess. You can check it easily. You don't event have to check it. Just think for a moment and please post how many items is in your model at the start of the for loop? And wysota asked you for it once and it was few days ago so maybe you found any way to do that in those days.
When you found the answer, then try to tell me what happens in line marked as "// 3".
If it's to difficult for you to open the Assistant (usually typing "assistant" in run command window (shortcut: WinLogo + R) is enough to run it) and searching there something about QStandardItemModel you can just click on this link: QStandardItemModel::item() and read the only sentence there about that method.
Finally, tell me also how many time the line "// 4" is reached/executed in your application?
Good luck in answers searching!

yuvaraj.yadav
2nd May 2009, 10:39
Hi

Thanks for your reply...


if delete the SetVisible (true) line ....... Simple my project is executed and nothing it showed ,even mainwindow too.

Here

My point of view

i need 24 items (rows)

My loop execute execute //line4 24 times, so i get 24 rows of tweets


If you don't mistake me can you provide me sample code...

It help for me to analyze and referring purpose...

I am struggling this issue last one week.

Thanks

Yuvaraj

yuvaraj.yadav
2nd May 2009, 10:42
In line 3 i am going to set every Item(row) width asequal as tweet resized width

faldzip
2nd May 2009, 12:19
i need 24 items (rows)

My loop execute execute //line4 24 times, so i get 24 rows of tweets
Wrong.
Your line "// 4" is executed exactly 0 times. Why? because your app crashes one line earlier, because:
Your model contains exactly 0 items.
What you trying then is to set size hint in 24 items but they don't exist. Where are you creating items? I answer for you this time: there is NO LINE of code in your app where you create item. So if you would take a look into docs and see what QStandardItemModel::item() method does, you would see that it returns 0 in your case, bacause there are no items at all. And how do you imagine setting size hint to NULL pointer?
You have to insert items to the model first, and then you can access items by item() method.

faldzip
2nd May 2009, 12:20
if delete the SetVisible (true) line ....... Simple my project is executed and nothing it showed ,even mainwindow too.
Because it crashes even before MainWindow is showed.

yuvaraj.yadav
2nd May 2009, 12:36
Thanks

Totally i confused . I referred the QArstractViewModel::item().....

There we set the rows and columns .....Here My tweets going to set row by row according to loop....

Already I asked you ,can you provide me one sample example ....

or where can i get sample example ......

Thanks

Yuvaraj R

faldzip
2nd May 2009, 12:54
Dude, you are not creating items any where.
What are doing is that you want to get the pointer to an item:


item(13);

this will return the pointer QStandardItem * to the item in row = 13. Then you want to assign some widget (your Twitt) to that item. How can you do this if you model is empty?
In your code you are not inserting items to the model. You are setting size hints to item which DON'T EXIST. There is no item at row = 13. There is no item in row = 0, 1, 2, 3, 4, 5... So how do you want to set the size hint to those items? How do you want to assign widgets to those items? You are getting NULL pointer (do you know whats that? please confirm!) and you want to set size hint to this. The ONLY result of that is segmentation fault! You have to insert some items to the model! There are several ways to do that. Just take a look in QStandardItemModel docs and/or some Qt Examples & Demos - for exapmle appendRow() method would be useful. The sample code is already on your hard drive for that last week, so why you can't just check in docs how you can insert an item to the model?
It takes less time than a week to get thorugh the examples and docs.

yuvaraj.yadav
2nd May 2009, 13:14
Thanks my Guru....


Now I understood my mistake.......


Here my code according to you......

Tweet *tweet = new Tweet(this);
QStandardItem *newItem = new QStandardItem;
QStandardItemModel ::appendRow(newItem);
ui->listWidget->setIndexWidget(newItem->index(),tweet);

This one is displaying empty mainwinow only...

faldzip
2nd May 2009, 18:13
okey, now you know how to put items to the QStandardItemModel.
But... your QStandardItemModel has nothing to do with your QListWidget... Change QListWidget to QListView, and than you have to set your model to list view, so the view knows what to display.

yuvaraj.yadav
3rd May 2009, 08:03
Hi

Thanks for your reply ... Now it is displaying my frame on listview....


Now problem is how do display the my 20 tweets in listview...

Here i used for loop....

But nothing happened ...

Another one How do insertRows in listview..

I tried with

QStandard ItemModel :: insertRows(20,1, newItems).... nothing happened

Here my total rows 20,counter value 1...

please explain me using loop how do display same my 20 tweets


please help me

Thanks

Yuvaraj

aamer4yu
3rd May 2009, 11:52
Read the docs properly, they are of great help.
From the docs -

bool QAbstractItemModel::insertRows ( int row, int count, const QModelIndex & parent = QModelIndex() ) [virtual]
On models that support this, inserts count rows into the model before the given row.

and as for you, count shud be 20,,,get the point ??

faldzip
3rd May 2009, 12:09
or just make the for loop and in every pass append one item to the model, get its index and set the Twitt widget for this.

yuvaraj.yadav
3rd May 2009, 13:11
Thanks for your reply...


I didn't get you..



for( int i =0; i<rowCount();i++)
{
QStandardItemModel::insertRow( i, newItem );
view->setIndexWidget( newItem->index(), tweet );
}

Can you give sample code

faldzip
3rd May 2009, 14:16
tell me what number you get from rowCount() at the start of the for loop?

yuvaraj.yadav
3rd May 2009, 14:28
one , am i correct..

We can display 24 items in listview..


please give one sample code

faldzip
3rd May 2009, 14:32
okej, use this code, but first remove QStandardItemModel inheritance from mainwindow.h


MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
ui->setupUi(this);

QStandardItemModel * model = new QStandardItemModel(this);
for (int i = 0; i < 24; ++i)
{
QStandardItem * item = new QStandardItem;
model->appendRow(item);
}

ui->listView->setModel(model);

for (int i = 0; i < 24; ++i)
{
Tweet * t = new Tweet(this);
t->resize(ui->listView->size().width(), 70);
model->item(i)->setSizeHint(t->size());
ui->listView->setIndexWidget(model->item(i)->index(), t);
}
}

And now take a one week free from work/school and spend it on learning C++ and reading docs. And try to do something by yourself next time - but not just guessing - just check what those methods, classes and C++ keywords and operators do! It's simple - you can just use Google (www.google.com (http://www.google.com)) to find C++ tutorial (and English Lessons/Dictionaries if you can understand docs - but how you can say that if dont mind even opening single document?)