Qt Read XML File - c++

I am trying to read an xml file in Qt, which I successfully generated using a different method. Here is my xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Project>
<EditorTheme>NULL</EditorTheme>
<Modules>
<Module>
<Name>Module_Renderer</Name>
<Position>471,164</Position>
<Size>200,100</Size>
<Locked>true</Locked>
<Visible>true</Visible>
</Module>
<Module>
<Name>Module_Console</Name>
<Position>200,229</Position>
<Size>256,192</Size>
<Locked>true</Locked>
<Visible>false</Visible>
</Module>
<Module>
<Name>Module_ResourceToolkit</Name>
<Position>1049,328</Position>
<Size>200,100</Size>
<Locked>true</Locked>
<Visible>true</Visible>
</Module>
<Module>
<Name>Module_CellEditor</Name>
<Position>542,564</Position>
<Size>200,100</Size>
<Locked>true</Locked>
<Visible>false</Visible>
</Module>
</Modules>
</Project>
And here is some code that I am using to parse this file:
Project ProjectLoader::loadLastProject( ConsoleModule* console ) {
Project project;
// load xml
QFile file( "C:/Users/Krynn/Desktop/LastProject.xml" );
if( !file.open( QFile::ReadOnly | QFile::Text ) ) {
// print error cannot open
}
QXmlStreamReader reader;
console->outputDisplay->append( "Test" );
reader.setDevice( &file );
reader.readNext();
while( !reader.atEnd() && !reader.hasError() ) {
reader.readNext();
if( reader.isStartElement() ) {
QString name = reader.name().toString();
if( reader.name() == "Project" ) {
reader.readNextStartElement();
if( reader.name().toString() == "EditorTheme" ) {
// Append Project theme
console->outputDisplay->append( "Theme Detected: " + reader.name().toString() + " " + reader.readElementText() );
}
reader.readNextStartElement();
if( reader.name().toString() == "Modules" ) {
// how do I proceed??
console->outputDisplay->append( QString( "" ) + " " + reader.name().toString() + " " + reader.readElementText() );
}
}
}
}
if( reader.hasError() ) {
console->outputDisplay->append( "XML error: " + reader.errorString() );
} else if( reader.atEnd() ) {
console->outputDisplay->append( "End of XML File Reached" );
}
file.close();
return project;
}
And here is some visual output for what that code gives me:
Really, I just don't know how I would go about loading all the module data within the xml file. I was using a plain text file previously to store all this stuff, but now I want to upgrade. Any help would be greatly appreciated.

Nevermind I figured it out.
Project ProjectLoader::loadLastProject( ConsoleModule* console ) {
Project project;
// load xml
QFile file( "C:/Users/Krynn/Desktop/LastProject.xml" );
if( !file.open( QFile::ReadOnly | QFile::Text ) ) {
// print error cannot open
}
QXmlStreamReader reader;
reader.setDevice( &file );
reader.readNext();
int count = 0;
while( !reader.atEnd() ) { //&& !reader.hasError()
reader.readNext();
if( reader.isStartElement() ) {
if( reader.name().toString() == "Module" ) {
WindowModuleSaveData data;
reader.readNextStartElement();
data.name = reader.readElementText(); // name
reader.readNextStartElement();
data.position = convertStringToQPoint( reader.readElementText() );
console->outputDisplay->append( convertQPointToString(data.position) );
reader.readNextStartElement();
data.size = convertStringToQSize( reader.readElementText() );
reader.readNextStartElement();
data.isLocked = reader.readElementText() == "true" ? true : false;
reader.readNextStartElement();
data.isVisible = reader.readElementText() == "true" ? true : false;
project.modules.push_back( data );
console->outputDisplay->append("Loaded A Module");
}
count++;
}
}
console->outputDisplay->append( QString::number( count ) );
if( reader.hasError() ) {
console->outputDisplay->append( "XML error: " + reader.errorString() );
} else if( reader.atEnd() ) {
console->outputDisplay->append( "End of XML File Reached" );
}
file.close();
return project;
}
The above code may be error prone, because it assumes what the next child may be instead of actually testing for it. Good enough for now though.

Related

How to add Shapefile to map?

What's The NameSpace for ShapeFile Class ?
my language is silverlight in Esri Map:
<esri:GraphicsLayer ShowLegend="false" ID="ResultsGraphicsLayer" />
<esri:GraphicsLayer ShowLegend="false" ID="MyGraphicsLayer" />
<esri:GraphicsLayer ShowLegend="false" ID="MySelectionGraphicsLayer" MouseEnter="GraphicsLayer_MouseEnter" MouseLeave="GraphicsLayer_MouseLeave"/>
<esri:GraphicsLayer ShowLegend="false" ID="IdentifyIconGraphicsLayer"/>
</esri:Map>
in codebehind:
private void openFileDialog_Click( object sender, RoutedEventArgs e )
{
//Create the dialog allowing the user to select the ".shp" and the ".dbf" files
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
if( !( ofd.ShowDialog() ?? false ) )
return;
//Get the file info objects for the SHP and the DBF file selected by the user
FileInfo shapeFile = null;
FileInfo dbfFile = null;
foreach( FileInfo fi in ofd.Files )
{
if( fi.Extension.ToLower() == ".shp" )
{
shapeFile = fi;
}
if( fi.Extension.ToLower() == ".dbf" )
{
dbfFile = fi;
}
}
//Read the SHP and DBF files into the ShapeFileReader
ShapeFile shapeFileReader = new ShapeFile();
if( shapeFile != null && dbfFile != null )
{
shapeFileReader.Read( shapeFile, dbfFile );
}
else
{
HtmlPage.Window.Alert( "Please select a SP and a DBF file to proceed." );
return;
}
//Add the shapes from the shapefile into a graphics layer named "shapefileGraphicsLayer"
//the greaphics layer should be present in the XAML or created earlier
GraphicsLayer graphicsLayer = MyMap.Layers[ "shapefileGraphicsLayer" ] as GraphicsLayer;
foreach( ShapeFileRecord record in shapeFileReader.Records )
{
Graphic graphic = record.ToGraphic();
if( graphic != null )
graphicsLayer.Graphics.Add( graphic );
}

C++ Text file Reading and Parsing for text-based adventure game

I'm a bit of a noob when it comes to programming, but as a small project I decided I'd try to make a VERY simple text-based adventure game just for some fun and practice. I have no idea how these types of games are normally made, but I decided to make a text file containing all the actual text rather than typing it all in the code, so here's what my "gamelocationdata.txt" file currently looks like.
[castleStart]
{
=castleStart=
You find yourself in a dark room inside a castle.
The walls are made of mossy stone and the entire room has a very eerie atmosphere.
There is a green bottle on the floor.
There are 2 exits, east and south.
Both exits are large doorways with grand arches.
You can see a large room through the south exit, but the east exit looks very dark and
somewhat frightening.
What will you do?
#"look arch" castleStartLookArch
#"look wall" castleStartLookWall
#"look bottle" castleStartLookBottle itemcond: hasBottle "0"
#"take bottle" castleStartLookBottle itemcond: hasBottle "0"
#"pick bottle" castleStartLookBottle itemcond: hasBottle "0"
#"go south" castleHall
#"go east" castleDark loccond: hasBeenCastleDark "0"
#"wait" castleStartWait
}
[castleStartLookArch]
{
=castleStart=
The arches above the doors look very fancy.
You can't quite figure out why this tiny room deserves to be decorated as such.
#(castleStart)
}
[castleStartLookWall]
{
=castleStart=
The wall is made of stone masonry in an old-fashioned way.
Some stones are covered in moss and there are cobwebs in the corners.
#(castleStart)
}
[castleStartWait]
{
=castleStart=
You sit still and admire the wall for a while.
Nothing happens.
#(castleStart)
}
[castleStartLookBottle]
{
=castleStart=
You pick the bottle up. It is covered in cobwebs.
The bottle is green and the label reads "1337". It contains a purple liquid.
Do you want to put the bottle in your backpack?
#"yes" castleStartTakeBottle
#"no" castleStartNoTakeBottle
}
[castleStartTakeBottle]
{
=castleStart=
You take the bottle and put it in your backpack.
+item: Bottle1337
+itemcond: hasBottle "1"
#(castleStart)
}
[castleStartNoTakeBottle]
{
=castleStart=
You put the bottle back down again.
#(castleStart)
}
[useBottle1337]
{
=curLocation=
You open the bottle and drink its contents.
It tastes very sweet.
You suddenly feel slightly stronger and more powerful.
+strength: 5
+remove_item: Bottle1337
#(castleStart)
}
[castleHall]
{
=castleHall=
You walk though the southern doorway and enter the grand hall of the castle.
It seems like the entire castle is just as old and worn out as the walls in that room,
though still very nicely decorated.
There are only a few candles on the walls, and they are somehow lit despite
the castle seeming very empty. There is not not a person to be seen.
You can go back north or proceed south through the hall.
#(castleStart)
}
[castleDark]
{
=castleStart=
You slowly tread into the dark room to the east, looking
around you as your surroundings get darker and darker.
Suddenly, you hear a noise. It sounds like the growling of an angry dog!
Horrified, you hastily turn around and run back.
+loccond: hasBeenCastleDark "1"
#(castleStart)
}
I realize I may have bitten of more than I can chew, but this is how the formatting I made up is supposed to work:
Example: [castleStart] is the name of a "location", and the curly
braces that come after encapsulate everything that has to do with that
location.
Example: =castleStart= is the location to print for the player when
they ask where they currently are.
The stuff that comes after that is what will be printed on screen when the player
"enters" that location.
After the location text, there are a bunch of options that all start
with a "#".
Example: #"wait" castleStartWait If the player types "wait", they will
be taken to the "location" named [castleStartWait].
Example: #"look bottle" castleStartLookBottle itemcond: hasBottle "0"
If the player types "look bottle", they will be taken to the location
named [castleStartLookBottle] as long as they meet the "item
requirement" that they do not already have the bottle.
Example: #"go east" castleDark loccond: hasBeenCastleDark "0" If the
player types "go east", they will be taken to the location named
[castleDark] as long as they meet the "location requirement" that they
haven't already been there.
Example: #(castleStart) This will use the same options as the ones listed in [castleStart].
Example: +strength: 5 This should add 5 points to the player's "strength" stat when they enter the location and print some hardcoded message like "You have acquired 5 strength points!"
Now, here's the problem: How do I write the function that reads and parses the data of a specific location and stores them in specific std::strings?
For example, if I do
readAndParseLocationData( castleStart );
it should look for [castleStart] in the text file, then read what's between the equals signs (=castleStart=) and store that in "std::string printLoc", then read the text after and store in a "std::string locText" and so on.
This is all the code I have so far:
//main.cpp
#include <iostream>
#include <string>
#include "ClearScreen.h"
#include "LocationData.h"
int main()
{
ClearScreen();
std::cout << "I am a banana!\n\n"; // this is just a test
readAndParseLocationData( "castleHall" );
printLocationData( "castleStart" ); // this is supposed to be used for debugging the location data by printing it.
return 0;
}
--
//LocationData.cpp
#include "LocationData.h"
#include <fstream>
#include <iostream>
#include <string>
void readAndParseLocationData( std::string location )
{
location.insert( 0,"[" );
location.append( "]" );
std::ifstream locfile( "gamelocationdata.txt" );
if( locfile.is_open() )
{
std::string line;
bool foundFile = false;
for( unsigned int curLine = 0; getline( locfile,line ); curLine++ )
{
if( line.find( location ) != std::string::npos )
{
std::cout << "found: " << location << ", line: " << curLine << "\n";
foundFile = true;
}
}
if( !foundFile )
{
std::cout << "\nERROR: Location " << location << " not found in data file!\n";
}
locfile.close();
}
else
{
std::cout << "\nERROR: Unable to open location data file!\n";
}
}
void printLocationData( std::string location )
{
//TODO: Implement
}
All I've managed to make it do (through extensive googling) is look for the location name and print what line it's on to the console.
I'm using Visual Studio Express 2013 on Windows 7.
I'd also love to hear if there is any way to improve my code or formatting in general!
It seems that what you want to do is parse the file just-in-time as you come across the locations you wish to access. This is a good idea if you expect your game to become too large to feasibly parse once and store in memory, but for a small example like this, it's probably unnecessary.
However, if you wish to implement this for learning purposes, there are a few things to look into. First of all, your current idea would involve re-parsing the file every time you want to look at the some location. A better idea would be to devise some kind of representation for the location data and implement a cache of some kind. A possible way to do this (only taking the names and location text into account) would be:
class Location
{
private:
std::string name;
std::string displayName;
std::string locationText;
}
std::unordered_map<std::string, Location> cache;
Location& readAndParseLocationData( std::string location )
{
//if we have already parsed this location
if (cache.count(location))
{
return cache[location];
}
else
{
Location parsed_location{};
//do the parsing
cache[location] = parsed_location;
}
}
In order to actually do the parsing, I would write a simple recursive descent parser. For your case, it would look something like this (in pseudocode):
Until we have found the location:
Look for a location
If this location matches:
Read the location into a string
Look for a opening brace
Read the location display name into a string
Read the rest into a string up until a closing brace
For future readers who happen to stumble upon this 2 year old question, here's the final code I ended up using to parse the location data.
(It's old and not pretty by any means, but note that the solution to my main problem was learning about std::getline and the various manipulation methods of std::string - mainly find() and substr().)
struct Location final
{
std::string displayName;
std::string optionsName;
std::string locationText;
std::string defaultOption;
std::string shop;
std::vector<int> battleLevel;
std::vector<int> battleChanceLevel;
std::vector<int> battleChancePercentage;
std::vector<std::string> battleEnemy;
std::vector<std::string> battleChanceEnemy;
std::vector<std::string> addItems;
std::vector<std::string> addWeapons;
std::vector<std::string> addConds;
std::vector<std::string> addStats;
std::vector<std::string> removeItems;
std::vector<std::string> removeWeapons;
std::vector<std::string> removeConds;
std::vector<std::string> removeStats;
std::unordered_set<std::string> options;
std::unordered_map<std::string, std::string> resultLoc;
std::unordered_map<std::string, std::string> conds;
};
std::unordered_map<std::string, Location> locationCache;
std::unordered_map<std::string, std::string> locationNewFileCache;
Location& loadLocationData( const std::string& location, const std::string& filename, const bool overRideData, const bool dataFile )
{
if( ::locationCache.count( location ) && overRideData == false ) // If we already parsed this location...
return ::locationCache[ location ]; // Return cached data.
else
{
auto filePath = std::string( "game/data/" );
if( !dataFile )
filePath.append( "locations/" );
std::ifstream locFile( filePath + filename );
if( locFile.is_open() )
{
bool foundLoc = false;
for( std::string line; std::getline(locFile, line); )
{
Location parsedLocation;
if( line.find( "[" + location + "]" ) != std::string::npos )
{
foundLoc = true;
// Parse optionsname/next filename.
std::string optsName; std::getline( locFile, optsName );
if( optsName.find( ".txt" ) != std::string::npos )
::locationNewFileCache[ location ] = optsName;
else
parsedLocation.optionsName = optsName;
// Parse display name.
std::string dispName; std::getline( locFile, dispName );
parsedLocation.displayName = dispName;
// Parse location text.
std::string locText;
for( std::string scanLine; ( (scanLine.empty()) ? true : scanLine.back() != '}' ) && std::getline( locFile, scanLine ); )
{
if( !scanLine.empty() && scanLine.front() == '{' )
locText = scanLine;
else
locText.append( "\n" + scanLine );
}
if( locText.size() >= 2 )
{
locText.erase( locText.begin() ); // Remove { at beginning.
locText.pop_back(); // Remove } at end.
}
parsedLocation.locationText = locText;
// Parse rest.
bool endReached = false;
for( std::string scanLine; !endReached && std::getline( locFile, scanLine ); )
{
if( !scanLine.empty() )
{
switch( scanLine.front() )
{
case '*': endReached = true; break; // END
case '#': // OPTION / DEFAULT OPTION
if( scanLine.at( 1 ) == '"' ) // OPTION
{
scanLine.erase( 0, 2 );
auto optionName = scanLine.substr( 0, scanLine.find( '\"' ) );
parsedLocation.options.insert( optionName );
scanLine.erase( 0, scanLine.find( '\"' ) + 2 );
auto optionResultLoc = scanLine.substr( 0, scanLine.find( ';' ) );
parsedLocation.resultLoc[ optionName ] = optionResultLoc;
scanLine.erase( 0, scanLine.find( ';' ) + 1 );
if( !scanLine.empty() ) // if the option has conditions...
{
auto condType = scanLine.substr( 0, scanLine.find( ':' ) );
scanLine.erase( 0, scanLine.find( ':' ) + 2 );
if( condType == "loccond" || condType == "itemcond" || condType == "statcond" )
parsedLocation.conds[ optionName ] = scanLine;
else
logError( "Invalid location data syntax in " + filename + "!", "Invalid condition" );
}
}
else if( scanLine.at( 1 ) == '(' ) // DEFAULT OPTION
{
scanLine.erase( 0, 2 );
parsedLocation.defaultOption = scanLine.substr( 0, scanLine.find( ')' ) );
}
else
logError( "Invalid location data syntax in " + filename + "!", "Neither option nor default option specified" );
break;
case '+': // ACTION (ITEM / STAT / CONDITION)
scanLine.erase( scanLine.begin() );
auto action = scanLine.substr( 0, scanLine.find( ':' ) );
scanLine.erase( 0, scanLine.find( ':' ) + 2 );
auto value = scanLine;
if( action == "item" )
parsedLocation.addItems.push_back( value );
else if( action == "remove_item" )
parsedLocation.removeItems.push_back( value );
else if( action == "weapon" )
parsedLocation.addWeapons.push_back( value );
else if( action == "remove_weapon" )
parsedLocation.removeWeapons.push_back( value );
else if( action == "itemcond" || action == "loccond" )
parsedLocation.addConds.push_back( value );
else if( action == "battle" )
{
auto enemyName = value.substr( 0, value.find( ' ' ) );
value.erase( 0, value.find( ' ' ) + 1 );
auto nEnemies = std::stoi( value.substr( 0, value.find( ',' ) ) );
value.erase( 0, value.find( ',' ) + 1 );
auto level = std::stoi( value );
for( auto i = 0; i < nEnemies; ++i )
{
parsedLocation.battleEnemy.push_back( enemyName );
parsedLocation.battleLevel.push_back( level );
}
}
else if( action == "battlechance" )
{
auto enemyName = value.substr( 0, value.find( ' ' ) );
value.erase( 0, value.find( ' ' ) + 1 );
auto chance = std::stoi( value.substr( 0, value.find( ',' ) ) );
value.erase( 0, value.find( ',' ) + 1 );
auto level = std::stoi( value );
parsedLocation.battleChanceEnemy.push_back( enemyName );
parsedLocation.battleChancePercentage.push_back( chance );
parsedLocation.battleChanceLevel.push_back( level );
}
else if( action == "shop" )
parsedLocation.shop = value;
else
parsedLocation.addStats.push_back( action + " " + value ); // Assume it's a stat.
break;
}
}
}
::locationCache[ location ] = parsedLocation;
return ::locationCache[ location ];
}
}
}
else
logError( "Unable to open location data file " + filename + "!" );
}
static Location dummyLocation;
return dummyLocation;
}

xml parsing in c++ using tinyxml

i am creating xml file in c++
i wrote the code like creating writing the xml file in c++ as shown below
const char* assign =
"<?xml version=\"1.0\" standalone='no' >\n"
"<office>"
"<work>file created</work>"
"</office>";
TiXmlDocument doc( "vls.xml" );
doc.Parse( assign );
if ( doc.Error() )
{
printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() );
exit( 1 );
}
doc.SaveFile();
bool loadOkay = doc.LoadFile();
if ( !loadOkay )
{
printf( "Could not load test file 'vls.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
exit( 1 );
}
else
printf(" 'vls.xml' loaded successfully");
but now i need only the data in the XMl file not the tags
guys plz help me.
I'd suggest reading the TinyXml documentation, more specifically the TiXmlElement documentation.
For your special case, I'd say it looks like that:
TiXmlElement * office = doc.FirstChildElement( "office" );
if( office )
{
TiXmlElement *work = office.FirstChildElement( "work" );
if( work )
{
printf("Work text: %s\n", work.GetText());
}
}
Although I'm not an expert with TinyXml.
FYI:
StackOverflow search function
Some - Answers - You - should have - considered ....
Please, search Google and StackOverflow before asking such trivial questions.

c++ dom parser problem

I want to change an XML file. I'm using DOM Parser. My XML file is the following:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.default.name</name>
<value> name</value>
</property>
</configuration>
I just want to remove the <value>name</name> node and put a new node <value>next</value>. How can I do this?
I wrote code in C++ also, but I'm stuck in the middle. What should I do? My code is the following:
#include<string.h>
#include<iostream>
#include<sstream>
#include<sys/types.h>
#include<unistd.h>
#include<errno.h>
#include<sys/stat.h>
#include "parser.hpp"
using namespace xercesc ;
using namespace std;
GetConfig::GetConfig()
{
XMLPlatformUtils::Initialize();
TAG_configuration =XMLString::transcode("configuration");
TAG_property = XMLString::transcode("property");
TAG_value=XMLString::transcode("value");
Tag_name=XMLString::transcode("name");
m_ConfigFileParser=new XercesDOMParser;
}
GetConfig::~GetConfig()
{
delete m_ConfigFileParser;
XMLString::release( &TAG_configuration );
XMLString::release( &TAG_property );
XMLString::release( &TAG_value );
XMLPlatformUtils::Terminate();
}
void GetConfig :: readConfigFile(string& configFile)
{
struct stat fileStatus;
int iretStat = stat(configFile.c_str(), &fileStatus);
if( iretStat == ENOENT )
throw ( std::runtime_error("Path file_name does not exist, or path is an empty string.") );
else if( iretStat == ENOTDIR )
throw ( std::runtime_error("A component of the path is not a directory."));
else if( iretStat == ELOOP )
throw ( std::runtime_error("Too many symbolic links encountered while traversing the path."));
else if( iretStat == EACCES )
throw ( std::runtime_error("Permission denied."));
else if( iretStat == ENAMETOOLONG )
throw ( std::runtime_error("File can not be read\n"));
// Configure DOM parser.
m_ConfigFileParser->setValidationScheme( XercesDOMParser::Val_Never );
m_ConfigFileParser->setDoNamespaces( false );
m_ConfigFileParser->setDoSchema( false );
m_ConfigFileParser->setLoadExternalDTD( false );
m_ConfigFileParser->parse( configFile.c_str() );
DOMDocument* xmlDoc = m_ConfigFileParser->getDocument();
DOMElement* elementRoot = xmlDoc->getDocumentElement();
DOMNodeList* children = elementRoot->getChildNodes();
int main()
{
string configFile="/home/manish.yadav/Desktop/simple.xml";
GetConfig appConfig;
appConfig.readConfigFile(configFile);
return 0;
}
Now I don't know how to traverse this document. Here are my questions:
How can I reach to <value>?
How can I change value of <value> name</value> to <value> next</value>?
My idea is to remove the entity and then add it again with different value, but I don't know how to do this, either. Please explain with example code, or suggest any other ideas on how to do this.
After m_ConfigFileParser->parse( configFile.c_str() ); do the following (considering "configuration" is the root element):
DOMDocument* doc = m_ConfigFileParser.getDocument();
DOMElement* root = dynamic_cast<DOMElement*>( doc->getFirstChild() );
if ( root ) {
DOMElement* property = dynamic_cast<DOMElement*>( root->getElementsByTagName( "property" )->item( 0 ) );
if ( property ) {
DOMElement* value = dynamic_cast<DOMElement*>( property->getElementsByTagName( "value" )->item( 0 ) );
if ( value ) {
value->setTextContent( " next" ); // this will update the element named "value"
}
}
}

open desktop using QText Browser

Right now I am displaying something like /home/binary/ in QText browser. Now I want the open the folder by clicking on this text. How to do that ? Thanks in advance
Here is my sample code. I am display the result
s
bool MainWindow::displayResult(multimap<string,
string> &resultMap, string &filePath)
{
multimap::iterator iter;
bool fileStatus = false;
int noOfLocFound = 0, forAppending = 0;
QString no;
noOfLocFound = resultMap.size();
if ( noOfLocFound != 0 )
ui->textBrowser->append( "<i>File found at <b>" + no.setNum (
noOfLocFound ) + " locations");
for ( forAppending = 0,iter = resultMap.begin(); iter !=
resultMap.end(); iter++,
forAppending++ )
{
string file = iter->first;
string dir = iter->second;
if ( forAppending == 0)
filePath.append(dir);
else
filePath.append(","+dir);
QString qdir = QString::fromStdString(dir);
cout << "Display";
ui->textBrowser->append( qdir );
fileStatus = true;
}
if ( fileStatus == false )
{
ui->textBrowser->append("File not
found");
return false;
}
return true;
}
By "open the folder", do you mean, open a file dialog for the user to select something inside of the given directory?
If so, you would probably want to connect your QTextBrowser's clicked signal to a slot that looked something like:
// connect events, in MyWindow constructor, or whereever...
connect(textbrowser, SIGNAL(mousePressEvent(QMouseEvent*)), this, SLOT(openFileDialog(QMouseEvent*)));
void MyWindow::openFileDialog(QMouseEvent* event) {
Q_UNUSED(event);
QStringList files = QFileDialog::getOpenFileNames(this, "Select a file...",
textbrowser.plainText());
// do something with the files here...
}