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

  • Home
  • SEARCH
  • 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 8331123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:19:26+00:00 2026-06-09T02:19:26+00:00

I am using Qt and I need some help How to declare QStringList variable

  • 0

I am using Qt and I need some help

  1. How to declare QStringList variable globally in Qt so that I can access it in any function?

  2. How to print all the stuff in QStringList(it contains the file path which it took from QFileDialog) to a lineEdit?

I tried:

ui->lineEdit->setText(filename);

But it gave me error error:QString to non-scalar type QStringList requested.
Please give me some examples.

  • 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-09T02:19:27+00:00Added an answer on June 9, 2026 at 2:19 am

    How to declare QStringList variable globally in Qt so that I can access it in any function

    Well this isn’t a Qt question, but a general C++ one (global variables are frowned upon these days, a more acceptable equivalent is the singleton, search SO for lots of examples). Nonetheless, one way of doing this would be create the QStringList as a static member of the class that instantiates the QFileDialog, the same class will be the one that retrieved it from the dialog anyway and by storing (and returning) it statically you effectively make it global:

    class A
    {
    public:
        void openFileDialog() { // Open the dialog, and store the results in list_. }
        static const QStringList& getFileList() { return list_; }
    private:
        static list_;
    }
    
    // Just call by:
    QStringList list = A::getFileList();
    

    How to print all the stuff in QStringList(it contains the file path which it took from QFileDialog)

    Yes, my QStringList contains only 1 string

    Well, if your QStringList only contains one string just use:

    ui->lineEdit->setText(list_[0]);
    

    Remember a QStringList is derived from QVector< QString >, so you can access the individual QStrings just like any element.

    Just to expand your first question, there an infinite number of ways a list of strings can be combined into a single one. But a very common (and easy) method with QStringList is to use join():

    QStringList list; list << "This" << "is" << "a" << "list.";
    list.join( " " ); // "This is a list. "
    

    I really recommend using the docs, Qt’s are brilliant .

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

Sidebar

Related Questions

I need some help on compiler flags in c++. I'm using a library that
I need some help using regex in java. Im trying to achieve 2 different
I need some help with overlaying views using the prism framework.Its a little more
I need some help extracting the following bits of information using regular expressions. Here
I need some help with an app i'm making using MapKit I'm struggling with
I need some help editing a csproj file using PowerShell. I basically need to
I'm trying to perform some realtime phone-number validation using javascript. I don't need help
I need some help implementing threading using Python 2.1. I would readily update to
I need some help with customizing JButton. I am using following extended method to
I need some help using a .NET Wrapper for Google chrome. The problem is

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.