How to add a relative path to the database in Qt - c++

In my project I have a database, eg Data.db. Using it in my code, I give a constant path / home / adam / cpp / etc .. I would like to use a relative path, how can I do this? in the .pro file? resources?
code:
bool LoginWindow::loginConnect()
{
loginDatabase = QSqlDatabase::addDatabase("QSQLITE");
loginDatabase.setDatabaseName("/home/jarek/ProjectInQt/BankManagment-Qt/BankManagment/sql/Login.db");
return loginDatabase.open() ? true : false;
}
I want relative path to Login.db

Related

PowerBI: Check if the folder/directory we are loading to exists or not using Power Query

I am a newbie in PowerBi and currently working on a POC where I need to load data from a folder or directory. Before this load, I need to check if
1) the respective folder exists
2) the file under the folder is with.csv extension.
Ex. Let suppose we have a file '/MyDoc2004/myAction.csv'.
Here first we need to check if MyDoc2004 exists and then if myAction file is with.csv extension.
Is there any way we can do this using Power Query?
1. Check if the folder exists
You can apply Folder.Contents function with the absolute path of the folder, and handle the error returned when the folder does not exist with try ... otherwise ... syntax.
let
absoluteFolderPath = "C:/folder/that/may/not/exist",
folderContentsOrError = Folder.Contents(absoluteFolderPath),
alternativeResult = """" & absoluteFolderPath & """ is not a valid folder path",
result = try folderContentsOrError otherwise alternativeResult
in
result
2. Check if the file is with .csv extension
I'm not sure what output you are expecting.
Here is a way to get the content of the file by full path including ".csv", or return an alternative result if not found.
let
absoluteFilePath = "C:/the/path/myAction.csv",
fileContentsOrError = File.Contents(absoluteFilePath),
alternativeResult = """" & absoluteFilePath & """ is not a valid file path",
result = try fileContentsOrError otherwise alternativeResult
in
result
If this is not what you are looking for, please update the question with the expected output.
Hope it helps.

gradle war rename file regular exp not working

Gradle war: rename files not working with regular expr.
war {
into "foo"
from ("hello/world") {
include "bar/config/*.xml"
// remove bar/ in the path
rename '(.*)/bar/config/(.*)', '$1/config/$2'
// tried
// rename 'bar/config/(.*)', 'config/$1'
}
}
Trying to rename
foo/bar/config/*.xml -> foo/config/*.xml
The entry path was not changed inside the war.
rename is operating on the file name, not the full path. To change the path you'll need access to a FileCopyDetails object. One way to do that is with filesMatching():
war {
from('hello/world') {
includeEmptyDirs = false
include 'bar/config/*.xml'
filesMatching('**/*.xml') {
it.path = it.path.replace('bar/', '')
}
}
}

How to check if a folder is writable using Qt

I am trying to check if a folder is writable so I can prompt an error dialog.
I am trying this:
QFileDevice::Permissions permissions_list = QFile( folderName ).permissions();
if ( permissions_list && QFileDevice::WriteUser )
{
}
but it does not work. It's the same for both writable folders and restricted ones.
use QFileInfo:
QFileInfo my_dir(folderName);
if(my_dir.isDir() && my_dir.isWritable()){
// Do something
}
but pay attention to this problem if you're on Windows

How to get a complete path from one with wildcards?

I have a path like:
C:\path\to\my*file\
and I would like to get the corresponding full path (if it exists):
C:\path\to\my1file\
I tried with this Qt code, but the result is the same path I had at the beginning:
QStringList filters;
filters << "C:/path/to/my*file/";
QDir dir;
dir.setNameFilters(filters);
QStringList dirs = dir.entryList(filters);
_path = dirs.at(0); // get the first path only
Shouldn't I get all the files/directories that get through the filter?
Why is _path equal to "C:/path/to/my*file/"?
Is it possible to do the same thing with C++98/STL only? (In this project I cannot use Boost/C++11).
Use filters to filter files/folders, and set the path in QDir object:
QStringList filters;
filters << "my*file";
QDir dir("C:/path/to/");
QStringList dirs = dir.entryList(filters);
if (dirs.size() > 0)
{
qDebug() << dirs.at(0);
}
Expanding file names is called globbing. On Windows the functions FindFirstFile() / FindNextFile() do globbing.

Find folder of the current javascript macro in iMacros?

I want to be able to reference the iMacros folder from my javascrip script in order to write:
retcode = iimPlay(folder + "/macro1.iim");
retcode = iimPlay(folder + "/macro2.iim");
instead of
retcode = iimPlay("test/macro1.iim");
retcode = iimPlay("test/macro2.iim");
I know it is possible in vbs but I don't know if that is the case in javascript.
it works in a similar way with javascript, here is example of the code:
var folder="c:\\data\\"
iimPlay(folder+"1.iim");
this code will run the 1.iim script from c:\data folder
You can make use of inbuilt !FOLDER_DATASOURCE variable to get folder of current javascript macro.
//Extract folder path of 'Datasources' folder (located inside 'iMacros' folder)
iimPlayCode("SET !EXTRACT {{!FOLDER_DATASOURCE}}");
var folderPath = iimGetExtract();
//Remove 'Datasources' from end of folder path string
folderPath = folderPath.slice(0,-11);
//Append 'Macros' to end of above path
folderPath = folderPath+"Macros\\";
alert(folderPath);
Performing above steps in single command.
//Extract folder path of 'Datasources' folder (located inside 'iMacros' folder)
iimPlayCode("SET !EXTRACT {{!FOLDER_DATASOURCE}}");
//Remove 'Datasources' from end of folder path string and append 'Macros'
var folderPath = iimGetExtract().slice(0,-11)+"Macros\\";
alert(folderPath);
Another possible approach is to replace 'Datasources' with 'Macros' in folder path.
//Extract folder path of 'Datasources' folder (located inside 'iMacros' folder)
iimPlayCode("SET !EXTRACT {{!FOLDER_DATASOURCE}}");
//Replace 'Datasources' with 'Macros' in folder path string
var folderPath = iimGetExtract().replace("Datasources","Macros\\");
alert(folderPath);
However it may create problem if folder path contains 'Datasources' anywhere else. You may use any of above methods as per your choice.
Once you get folder path of 'Macros' folder, you can use it like.
retcode = iimPlay(folderPath + "macro1.iim");