I'm writing a program in C++ and qt4 that is supposed to generate a various number (hundreds )of clickable links in a QTextBrowser depending on data from input files.
The idea is that when the user clicks one of these links a value will be passed to a function named 'on_QTextBrowser_anchorClicked(QUrl)'.
I have created a QTextBrowser which displays HTML code and I manage to create different links to every element added. The problem lies within passing the Url defined in href="URL" to the QUrl.
When setOpenLinks for the QTextBrowser is "true", and I print the URL I get the correct result. But I can't pass this URL (which is a value and not a real URL) to a function. When setOpenLinks is "false", the anchorClicked(Url) function passes "" as the Url and here I would like to have the URL printed when setOpenLinks=true.
How can I achieve this? Is there a better way (probably is) to connect a various number (approx. between 50-1000) of generated links to a function using QTextBrowser.
My code:
Compassindex.cpp
void CompassIndex::on_seqBrowser_anchorClicked(QUrl input)
{
QString Input = input.toString();
QByteArray nByte = Input.toUtf8();
std::cerr<<Input.data(); //Print Url on the screen to ensure value is passed
}
void CompassIndex::readfile()
{
QString Line;
Int number_out=0;
... //Imports data that will be printed in the QTextBrowser
... //loop for creating links for n number of elements
Line="<a href=\"";
Line+=number_out; //the value (fake Url) that I want to pass to anchorClicked()
Line+="\">";
Line+=nameArr[n]; //inserts the name for the link
Line+="</a>";
number_out++;
...
ui->seqBrowser->insertHtml(Line);
... //end of loop
}
Many thanks for your reply!