I have a file called DBFile. I am using the following code:
QString DBfile ="C:/Users/E543925/Desktop/VikuTB.xml"; QFile newFile(DBfile); newFile.open( QIODevice::WriteOnly);
Now I want to write something inside the file if it is empty. How to check if a file is empty or not in Qt?
add the add flag and check the pointer insert:
pointer
newFile.open( QIODevice::WriteOnly|QIODevice::Append ); if (newFile.pos() == 0) { // is empty } else { // some data inside }
disclaimer: unverified code, now I will take the time to try ...
Edit: Checked seems to work well ...
Check file size before opening newFile.size ()
Source: https://habr.com/ru/post/1433198/More articles:How to autoload a directory in Silex - phpSendGrid SMTP API - phpSendGrid - NoClassDeffoundError with sendgrid-java.jar - javaCodeigniter do_upload not responding on production server - phpSoapObject Result returns anyType {} as value when migrating complexType object - androidSendgrid Java Doesn't work in Maven - javamysql structural replication from master to slave with slave data intact - phphow macros can be evaluated using clojurescript repl - clojureSymmetric Encryption Algorithm Function - c #Using Multiple File Inheritance in Ruby - ruby | fooobar.comAll Articles