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. -
-
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" -
@ 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....
-