Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

QStringList Class Reference

The QStringList class provides a list of strings. More...

#include </home/clem/local/src/opie/qmake/include/qstringlist.h>

Inheritance diagram for QStringList:

Inheritance graph
[legend]
Collaboration diagram for QStringList:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 QStringList ()
 QStringList (const QStringList &l)
 QStringList (const QValueList< QString > &l)
 QStringList (const QString &i)
 QStringList (const char *i)
void sort ()
QString join (const QString &sep) const
QStringList grep (const QString &str, bool cs=TRUE) const
QStringList grep (const QRegExp &expr) const

Static Public Member Functions

static QStringList fromStrList (const QStrList &)
static QStringList split (const QString &sep, const QString &str, bool allowEmptyEntries=FALSE)
static QStringList split (const QChar &sep, const QString &str, bool allowEmptyEntries=FALSE)
static QStringList split (const QRegExp &sep, const QString &str, bool allowEmptyEntries=FALSE)

Detailed Description

The QStringList class provides a list of strings.

It is used to store and manipulate strings that logically belong together. Essentially QStringList is a QValueList of QString objects. Unlike QStrList, which stores pointers to characters, QStringList holds real QString objects. It is the class of choice whenever you work with Unicode strings. QStringList is part of the Qt Template Library.

Like QString itself, QStringList objects are implicitly shared. Passing them around as value-parameters is both fast and safe.

Strings can be added to a list using append(), operator+=() or operator<<(), e.g.

    QStringList fonts;
    fonts.append( "Times" );
    fonts += "Courier";
    fonts += "Courier New";
    fonts << "Helvetica [Cronyx]" << "Helvetica [Adobe]";

String lists have an iterator, QStringList::Iterator(), e.g.

    for ( QStringList::Iterator it = fonts.begin(); it != fonts.end(); ++it ) {
        cout << *it << ":";
    }
    cout << endl;
    // Output:
    //  Times:Courier:Courier New:Helvetica [Cronyx]:Helvetica [Adobe]:

Many Qt functions return const string lists; to iterate over these you should make a copy and iterate over the copy.

You can concatenate all the strings in a string list into a single string (with an optional separator) using join(), e.g.

    QString allFonts = fonts.join( ", " );
    cout << allFonts << endl;
    // Output:
    //  Times, Courier, Courier New, Helvetica [Cronyx], Helvetica [Adobe]

You can sort the list with sort(), and extract a new list which contains only those strings which contain a particular substring (or match a particular regular expression) using the grep() functions, e.g.

    fonts.sort();
    cout << fonts.join( ", " ) << endl;
    // Output:
    //  Courier, Courier New, Helvetica [Adobe], Helvetica [Cronyx], Times

    QStringList helveticas = fonts.grep( "Helvetica" );
    cout << helveticas.join( ", " ) << endl;
    // Output:
    //  Helvetica [Adobe], Helvetica [Cronyx]

Existing strings can be split into string lists with character, string or regular expression separators, e.g.

    QString s = "Red\tGreen\tBlue";
    QStringList colors = QStringList::split( "\t", s );
    cout << colors.join( ", " ) << endl;
    // Output:
    //  Red, Green, Blue

Definition at line 51 of file qstringlist.h.


Constructor & Destructor Documentation

QStringList::QStringList  )  [inline]
 

Creates an empty string list.

Definition at line 54 of file qstringlist.h.

QStringList::QStringList const QStringList l  )  [inline]
 

Creates a copy of the list l. This function is very fast because QStringList is implicitly shared. In most situations this acts like a deep copy, for example, if this list or the original one or some other list referencing the same shared data is modified, the modifying list first makes a copy, i.e. copy-on-write. In a threaded environment you may require a real deep copy see QDeepCopy.

Definition at line 55 of file qstringlist.h.

QStringList::QStringList const QValueList< QString > &  l  )  [inline]
 

Constructs a new string list that is a copy of l.

Definition at line 56 of file qstringlist.h.

QStringList::QStringList const QString i  )  [inline]
 

Constructs a string list consisting of the single string i. Longer lists are easily created as follows:

    QStringList items;
    items << "Buy" << "Sell" << "Update" << "Value";

Definition at line 57 of file qstringlist.h.

References QValueList< T >::append().

QStringList::QStringList const char *  i  )  [inline]
 

Constructs a string list consisting of the single latin-1 string i.

Definition at line 59 of file qstringlist.h.

References QValueList< T >::append().


Member Function Documentation

QStringList QStringList::fromStrList const QStrList ascii  )  [static]
 

Converts from an ASCII-QStrList ascii to a QStringList (Unicode).

Definition at line 367 of file qstringlist.cpp.

References s.

Referenced by Konsole::init().

QStringList QStringList::grep const QRegExp expr  )  const
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns a list of all the strings that match the regular expression expr.

Definition at line 321 of file qstringlist.cpp.

References QValueList< QString >::begin(), and QValueList< QString >::end().

QStringList QStringList::grep const QString str,
bool  cs = TRUE
const
 

Returns a list of all strings containing the substring str.

If cs is TRUE, the grep is done case-sensitively; otherwise case is ignored.

Definition at line 303 of file qstringlist.cpp.

References QValueList< QString >::begin(), and QValueList< QString >::end().

Referenced by Passwd::addGroupMember(), MainWindowImp::addProfile(), UserDialog::editUser(), Process::exec(), OpieFtp::fillCombo(), AdvancedFm::fillCombo(), OpieFtp::fillRemoteCombo(), Interfaces::isAuto(), OPackageManager::loadAvailablePackages(), OPackageManager::loadInstalledPackages(), MultiauthConfig::loadPlugins(), QMakeProject::parse(), DingWidget::parseInfo(), SmtpHandler::readyRead(), AdvancedFm::removeCustomDir(), Passwd::searchGroup(), Passwd::searchUser(), and QProcess::start().

QString QStringList::join const QString sep  )  const
 

Joins the string list into a single string with each element separated by the string sep (which can be empty).

See also:
split()

Definition at line 338 of file qstringlist.cpp.

References QValueList< QString >::begin(), QValueList< QString >::end(), FALSE, and TRUE.

Referenced by OPimNotifyManager::alarmsFromString(), OPimNotifyManager::alarmsToString(), Opie::OPimNotifyManager::alarmsToString(), ServerPI::backupRestoreGzip(), MakefileGenerator::build_args(), ConfigDlg::ConfigDlg(), PPPData::deleteAccount(), PPPData::deleteDevice(), DevicesWidget::DevicesWidget(), Categories::displaySingle(), Qsmb::DoIt(), QMakeProject::doProjectTest(), QMakeProject::doVariableReplace(), Categories::dump(), MakefileGenerator::generateDependencies(), NetworkSettingsData::generateSettings(), PPPData::getDevicesNamesList(), ProjectGenerator::getWritableVar(), NmakeMakefileGenerator::init(), MingwMakefileGenerator::init(), BorlandMakefileGenerator::init(), MakefileGenerator::init(), OJanusWidget::InsertTreeListItem(), AppLnk::invoke(), StringParser::join(), main(), operator<<(), Opie::OPimTodo::OPimTodo(), OTodo::OTodo(), QMakeProject::parse(), parse(), DingWidget::parseInfo(), ContactEditor::parseName(), PPPData::PPPData(), ServerPI::process(), proFileTagMap(), QMakeProject::read(), QSettings::readEntry(), PlayListWidget::readpodcast(), OPimNotifyManager::remindersToString(), Opie::OPimNotifyManager::remindersToString(), OContact::removeEmail(), Contact::removeEmail(), Opie::OPimContact::removeEmail(), MainWindowImp::removeProfile(), System::runAsRoot(), Qsmb::runCommand(), ContactEditor::saveEntry(), DateBook::saveSettings(), DocumentList::sendAllDocLinks(), ServerDTP::sendGzipFile(), OJanusWidget::setFolderIcon(), InputDevice::setInfo(), CardDevice::setInfo(), NetworkRun::setMyState(), BluetoothRFCOMMRun::setMyState(), Opietooth2::OTSniffing::SLOT_Trace(), QSettings::subkeyList(), OTodoAccessXML::todo(), OTodoAccessXML::toString(), Opie::OPimTodoAccessXML::toString(), BorlandMakefileGenerator::writeBorlandParts(), QSettings::writeEntry(), Profile::writeEntry(), MakefileGenerator::writeInstalls(), UnixMakefileGenerator::writeMakeParts(), MakefileGenerator::writeMakeQmake(), NmakeMakefileGenerator::writeNmakeParts(), WLANImp::writeOpts(), VcprojGenerator::writeSubDirs(), MakefileGenerator::writeUicSrc(), and MainWindowImp::~MainWindowImp().

void QStringList::sort  ) 
 

Sorts the list of strings in ascending case-sensitive order.

Sorting is very fast. It uses the Qt Template Library's efficient HeapSort implementation that has a time complexity of O(n*log n).

If you want to sort your strings in an arbitrary order consider using a QMap. For example you could use a QMap<QString,QString> to create a case-insensitive ordering (e.g. mapping the lowercase text to the text), or a QMap<int,QString> to sort the strings by some integer index, etc.

Definition at line 181 of file qstringlist.cpp.

References qHeapSort().

Referenced by StartMenu::createMenuEntries(), OContactFields::detailsfields(), Opie::OPimContactFields::detailsfields(), Categories::displaySingle(), QMakeProperty::exec(), OContactFields::fields(), Opie::OPimContactFields::fields(), PackageList::getSections(), PackageList::getSubSections(), Categories::labels(), QGPluginManager::library(), OPackageManager::loadAvailablePackages(), OPackageManager::loadInstalledPackages(), LauncherIconView::mimeTypes(), LibraryDialog::onButtonSearch(), OContactFields::personalfields(), Opie::OPimContactFields::personalfields(), OContactFields::phonefields(), Opie::OPimContactFields::phonefields(), NotesControl::populateBox(), Bartender::showSearchResult(), Checkbook::slotEditTran(), Checkbook::slotNewTran(), OContactAccessBackend_XML::sorted(), UserDialog::UserDialog(), QMakeProperty::value(), and DspMakefileGenerator::writeDspParts().

QStringList QStringList::split const QRegExp sep,
const QString str,
bool  allowEmptyEntries = FALSE
[static]
 

Splits the string str into strings wherever the regular expression sep occurs, and returns the list of those strings.

If allowEmptyEntries is TRUE, an empty string is inserted in the list wherever the separator matches twice without intervening text.

For example, if you split the string "a,,b,c" on commas, split() returns the three-item list "a", "b", "c" if allowEmptyEntries is FALSE (the default), and the four-item list "a", "", "b", "c" if allowEmptyEntries is TRUE.

If sep does not match anywhere in str, split() returns a list consisting of the single string str.

See also:
join() QString::section()

Definition at line 264 of file qstringlist.cpp.

References i, l, QString::length(), QRegExp::matchedLength(), QString::mid(), QString::null, and QRegExp::search().

QStringList QStringList::split const QChar sep,
const QString str,
bool  allowEmptyEntries = FALSE
[static]
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This version of the function uses a QChar as separator, rather than a regular expression.

See also:
join() QString::section()

Definition at line 195 of file qstringlist.cpp.

References split().

QStringList QStringList::split const QString sep,
const QString str,
bool  allowEmptyEntries = FALSE
[static]
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This version of the function uses a QString as separator, rather than a regular expression.

If sep is an empty string, the return value is a list of one-character strings: split( QString( "" ), "four" ) returns the four-item list, "f", "o", "u", "r".

If allowEmptyEntries is TRUE, an empty string is inserted in the list wherever the separator matches twice without intervening text.

See also:
join() QString::section()

Definition at line 218 of file qstringlist.cpp.

References QString::find(), i, l, QString::length(), QString::mid(), and QString::null.

Referenced by IRCServerEditor::accept(), ListEdit::addData(), OPimNotifyManager::alarmsFromString(), Opie::OPimNotifyManager::alarmsFromString(), DspMakefileGenerator::beginGroupForFile(), BenchmarkInfo::BenchmarkInfo(), OContact::childrenList(), Contact::childrenList(), Opie::OPimContact::childrenList(), ContactEditor::chooserChange(), createDir(), IRCConnection::dataReady(), OTodoAccessBackendSQL::date(), Opie::OPimTodoAccessBackendSQL::date(), EmailListItem::dateFromULCString(), PPPData::deleteAccount(), PPPData::deleteDevice(), OipkgPackage::details(), DocLnkSet::DocLnkSet(), QMakeProject::doProjectTest(), doqcopimpl(), QMakeProject::doVariableReplace(), BuzzWord::drawGrid(), OContact::emailList(), Contact::emailList(), Opie::OPimContact::emailList(), DspMakefileGenerator::endGroups(), Process::exec(), System::execAsUser(), QCopLnk::execute(), AppLnk::execute(), AppLauncher::execute(), AppLauncher::executeBuiltin(), CHM::FillHomeContent(), ORecur::fromMap(), OEvent::fromMap(), Opie::OPimRecurrence::fromMap(), Opie::OPimEvent::fromMap(), ANetwork::generateFile(), BatteryStatus::getProcApmStatusIpaq(), Swapfile::getStatusPcmcia(), CardMonitor::getStatusPcmcia(), Qsmb::hostSelected(), Qtopia::Record::idsFromString(), NmakeMakefileGenerator::init(), DspMakefileGenerator::init(), MingwMakefileGenerator::init(), BorlandMakefileGenerator::init(), UnixMakefileGenerator::init(), MakefileGenerator::init(), MetrowerksMakefileGenerator::init(), Opie::Core::Internal::GenuineIntel::init(), UnixMakefileGenerator::init2(), PickboardPicks::initialise(), VcprojGenerator::initOld(), MakefileGenerator::initOutPaths(), InputDialog::InputDialog(), Interfaces::Interfaces(), Global::invoke(), OPIE::languageList(), QSettings::lastModificationTime(), LibraryDialog::Library(), OpieTooth::RfCommConfHandler::load(), FunctionKeyboardConfig::load(), FunctionKeyboard::load(), MimeType::loadExtensions(), SFCave::loadReplay(), DateBook::loadSettings(), MultiauthConfig::loadUsers(), main(), MainWindowImp::MainWindowImp(), Multikey::message(), OFileSelector::OFileSelector(), Opie::Ui::OFileSelector::OFileSelector(), OListViewDemo::OListViewDemo(), operator<<(), IRCMessage::params(), QMakeProject::parse(), OpieTooth::Parser::parse(), NHcfg::parseCalc(), OpieTooth::Manager::parseConnections(), IRCMessageParser::parseCTCPDCC(), OpieTooth::Manager::parseHCIOutput(), WLANImp::parseKeyStr(), ContactEditor::parseName(), VCLinkerTool::parseOption(), OpieObex::Obex::parseOut(), OpieObex::BtObex::parseOut(), parsePid(), ServerPI::parsePort(), IMAPResponseParser::parseResponse(), LibraryDialog::parseSearchResults(), parseTime(), NHcfg::parsevalue(), Opie::OPimContactAccessBackend_VCard::parseVObject(), ServerPI::process(), QCopBridgePI::process(), proFileTagMap(), qmake_mkspec_paths(), qt_makeFilterList(), KateConfig::read(), ConfigEx::read(), Config::read(), KVNCBookmarkDlg::readBookmarks(), QSettings::readEntry(), KateConfig::readIntListEntry(), PackageManagerSettings::readIpkgConfig(), QMakeMetaInfo::readLibtoolFile(), QSettings::readListEntry(), KateConfig::readListEntry(), Config::readListEntry(), WLANModule::receive(), QCopWatcher::received(), System::refreshStatistics(), OPimNotifyManager::remindersFromString(), Opie::OPimNotifyManager::remindersFromString(), MainWindowImp::removeProfile(), OContactAccessBackend_SQL::requestNonCustom(), TypeCombo::reread(), Qt3::QTextParagraph::richText(), PPPData::save(), Qsmb::scan(), Qt3::QTextEdit::scrollToAnchor(), QCopBridge::sendDesktopMessageOld(), Cfg::setCategories(), ODateBookAccessBackend_XML::setField(), Opie::ODateBookAccessBackend_XML::setField(), AGPRSDevice::setSpecificAttribute(), IrdaApplet::showDiscovered(), Qtopia::simplifyMultiLineSpace(), NetworkEdit::SLOT_NetmaskModified(), MyProcess::SLOT_Stderr(), MyProcess::SLOT_Stdout(), OFileViewFileListView::slotClicked(), Opie::Ui::Internal::OFileViewFileListView::slotClicked(), OFileViewFileListView::slotCurrentChanged(), Opie::Ui::Internal::OFileViewFileListView::slotCurrentChanged(), FileTransfer::slotProgress(), FileTransfer::slotRead(), ViewMail::slotReply(), OpieTooth::Manager::slotSignalStrengthOutput(), split(), Passwd::splitGroupEntry(), Passwd::splitPasswdEntry(), QProcess::start(), strToColor(), QSettings::subkeyList(), Swapfile::Swapfile(), OTodoAccessXML::todo(), Opie::OPimTodoAccessXML::todo(), OTodoAccessBackendSQL::todo(), FileSelector::typeSelected(), FileBrowser::updateDirMenu(), use_net2003_version(), validIP(), VersionInfo::VersionInfo(), WLANImp::WLANImp(), ProjectBuilderMakefileGenerator::writeMakeParts(), MetrowerksMakefileGenerator::writeMakeParts(), and ProjectBuilderMakefileGenerator::writeSubdirs().


The documentation for this class was generated from the following files:
Generated on Sat Nov 5 17:49:05 2005 for OPIE by  doxygen 1.4.2