Sorting a .srt file for vlc player
-
've created a .srt file using
@
QTextStream out(AjayFileD);
out<<"\n"<<strc<<",000"<<"-->"<<strc<<",999"<<"\n";
@
and const char *strc has the pause time.If i pause at 1 min 42 seconds,the first line is written to a .srt and at 16 min 59 seconds,the second line is written to a .srt file
@00:01:42,000-->00:01:42,999
00:16:59,000-->00:16:59,999
@
now if i go back and pause at 10 minutes,this line is written
@00:10:00,000-->00:10:00,999
@
and the entire file looks like this
@00:01:42,000-->00:01:42,999
00:16:59,000-->00:16:59,999
00:10:00,000-->00:10:00,999
@
but i want it to look like this
@00:01:42,000-->00:01:42,999
00:10:00,000-->00:10:00,999
00:16:59,000-->00:16:59,999
@i want all the 'pause time' to be sorted in ascending order in the .srt file.
however,I'm not able to sort them in ascending order,please suggest some method to sort contents of .srt file in qt. -
Put each line in a single QString, put the QString into a QStringList and sort it afterwards:
@
QStringList pauseTimes;pauseTimes << QString("%1,00-->%2,999").arg(strc).arg(strc);
pauseTimes.sort();
QTextStream out(file);
out << pauseTimes.join("\n");
@ -
[[blank-post-content-placeholder]]
-
i commented these lines
@ // QTextStream out(AjayFileD);
//out<<"\n"<<strc<<",000"<<"-->"<<strc<<",999"<<"\n";@and i added this code
@QStringList pauseTimes;pauseTimes << QString("%1,00-->%2,999").arg(strc).arg(strc); pauseTimes.sort(); QTextStream out(AjayFileD); out << pauseTimes.join("\n");@
thank you sir, but i'm getting this error
"collect2: ld returned 1 exit status" -
Go to the windows/tab with the complete output of your compiler and linker. It tells you which symbols are missing. Without that information we cannot advise further.
-
the previous error “collect2: ld returned 1 exit status” is solved,it was just a typing error,i'm getting the subtitles but it is not getting sorted,even though there is no error,pls can you suggest
-
also I've used @out << "\n" << pauseTimes.join("\n") << "\n" ;
@ instead of just @out << pauseTimes.join("\n");@ -
perhaps you can post your current code and the result you now get?
-
@ QStringList pauseTimes;
pauseTimes << QString("%1,000-->%2,999").arg(strc).arg(strc); pauseTimes.sort();
QTextStream out(AjayFileD);
out << "\n" << pauseTimes.join("\n") << "\n" ;@
the same code suggested by volker, and the result
00:00:00,000-->00:00:00,99900:15:34,000-->00:15:34,999
00:34:39,000-->00:34:39,999
00:05:28,000-->00:05:28,999
1:32:35,000-->1:32:35,999
1:15:11,000-->1:15:11,999
00:12:54,000-->00:12:54,999
as you can see the pause times are not getting sorted in ascending order,i think it's just some small change but I'm stuck and btw i'm a beginner -
Hi,
whatever you do, I checked the following code and it's output:
@
int main(int argc, char *argv[])
{
QStringList pauseTimes;
pauseTimes << QLatin1String("00:00:00,000—>00:00:00,999");
pauseTimes << QLatin1String("00:15:34,000—>00:15:34,999");
pauseTimes << QLatin1String("00:34:39,000—>00:34:39,999");
pauseTimes << QLatin1String("00:05:28,000—>00:05:28,999");
pauseTimes << QLatin1String("1:32:35,000—>1:32:35,999");
pauseTimes << QLatin1String("1:15:11,000—>1:15:11,999");
pauseTimes << QLatin1String("00:12:54,000—>00:12:54,999");std::wcout << std::endl << (wchar_t*)(pauseTimes.join("\n").utf16()) << std::endl ; std::wcout << L"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl; pauseTimes.sort(); std::wcout << std::endl << (wchar_t*)(pauseTimes.join("\n").utf16()) << std::endl ; return 0;
}
@The output was:
@
00:00:00,000ù>00:00:00,999
00:15:34,000ù>00:15:34,999
00:34:39,000ù>00:34:39,999
00:05:28,000ù>00:05:28,999
1:32:35,000ù>1:32:35,999
1:15:11,000ù>1:15:11,999
00:12:54,000ù>00:12:54,99900:00:00,000ù>00:00:00,999 00:05:28,000ù>00:05:28,999 00:12:54,000ù>00:12:54,999 00:15:34,000ù>00:15:34,999 00:34:39,000ù>00:34:39,999 1:15:11,000ù>1:15:11,999 1:32:35,000ù>1:32:35,999 @ For me, the output looks sorted....
-
yeah thanks a lot,this is what i want,however i'm not entering the pause time manually,the pause time will be in const char *strc as soon as i press the pause button of the player,i'll use your code and post if i have any problem
thanks once again -
is the content of the array really 8 strings? or perhaps one multiline string?
-
no,i've just hit the pause button 8 times,so eight outputs,i can get this written into the file as many times as i like,so it is not just 8 strings ,the only problem is sorting and i'll use your code for that
-
You will need to store the stop points in a QStringList - or re-read the file, add the new line, sort an overwrite the existing data. You don't expect the file to sort automagically, do you?
-
thank you,i'll try