Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8471049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:41:22+00:00 2026-06-10T16:41:22+00:00

In CSharp it’s as simple as writing: listBox1.Items.Add("Hello"); listBox1.Items.Add("There"); foreach (string item in listBox1.Items

  • 0

In CSharp it’s as simple as writing:

listBox1.Items.Add("Hello");
listBox1.Items.Add("There");

foreach (string item in listBox1.Items )
{
    MessageBox.Show(item.ToString());
}

and I can easily add different objects to a list box and then retrieve them using foreach.

I tried the same approach in Qt 4.8.2 but it seems they are different. Though they look very similar at the first. I found that Qt supports foreach so I went on and tried something like:

foreach(QListWidgetItem& item,ui->listWidget->items())
{
    item.setTextColor(QColor::blue());
}

which failed clearly. It says the items() needs a parameter which confuses me. I am trying to iterate through the ListBox itself, so what does this mean? I tried passing the ListBox object as the parameter itself this again failed too:

foreach(QListWidgetItem& item,ui->listWidget->items(ui->listWidget))
{
    item.setTextColor(QColor::blue());
}

So here are my questions:

  • How can I iterate through a QListWidget items in Qt?
  • Can I store objects as items in QListWidgets like C#?
  • How can I convert an object in QListWidgets to string (C#s ToString counter part in Qt) ?

(Suppose I want to use a QMessageBox instead of that setTextColor and want to print out all string items in the QlistWidget.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:41:24+00:00Added an answer on June 10, 2026 at 4:41 pm

    I don’t think the items function does what you think it does. It sounds like it’s for decoding MIME data, not getting a list of all the items in the widget.

    I don’t actually see any function to do exactly what you want, sadly. You could probably use findItems as a workaround, but that seems ugly, if not downright abusive… At least you can still use the item function with good old for loops – they’re not that much more typing:

    for(int i = 0; i < listWidget->count(); ++i)
    {
        QListWidgetItem* item = listWidget->item(i);
        //Do stuff!
    }
    

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, there are mongodb-csharp simple-mongodb NoRM as C# drivers for MongoDB available. Which one
Is there an ObjectStore implmentation for csharp that allows be to generate string handles
In the Open with menu of a .cs file there's Csharp editor and Csharp
I am writing a csharp windows form application which attempts to check for the
Is there an inexpensive way to concatenate integers in csharp? Example: 1039 & 7056
The following CSharp Code(just sample): Console.WriteLine(Searching file in...); foreach(var dir in DirList) { Console.WriteLine(dir);
i have code in csharp that returns this string: {'dateTimeFormat': 'iso8601', 'wikiURL': http://simile.mit.edu/shelf/ ,
I am using .NET 2.0. My Csharp Application will cursh sometime. And there are
Playing around in Mono 2.10 REPL: csharp> string a = true; csharp> a.ToBoolean(CultureInfo.InvariantCulture); {interactive}(1,4):
Is there a way to apply several different csharp generic constraints to the same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.