I've to compare and highlight differences between two similar text files. I'm using QT 4.8 on VC 2010 and C++ as the programming language. After researching, I've found the google-diff-match-patch library which is available in QT platform.
https://code.google.com/p/google-diff-match-patch/

Using the library, I've been trying to align both the text files so that similar lines appear on the same line.
I don't find any good way to add newline wherever appropriate on either left or right text so that similar text appear on the same line for side-by-side comparison.

Please suggest the best way based on QT & diff match patch QT library.

for eg:-
Qt Code:
  1. QString leftText = "Hello World\nTest1 Wo23\n\nTest4";
  2. QString rightText = "Goodmorning World\n\nTest2 Wo33\nTest5";
To copy to clipboard, switch view to plain text mode 

After alignment the result should be
Qt Code:
  1. leftText = "Hello World\n\nTest1 Wo23\n\nTest4"; //added '\n' in second line to align with similar line in 3rd line
  2. rightText = "Goodmorning World\n\nTest2 Wo33\n\nTest5"; //added '\n' in 5th line to align with similar line in 7th line
To copy to clipboard, switch view to plain text mode 

Above is simple example, but in real-world I'm dealing with complex left text and right text of two files where similar line may be few lines below or above and empty lines needs to be created in between.