How to check if a folder is writable using Qt - c++

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

Related

How to add a relative path to the database in Qt

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

C++/CX - GetFileAsync throws breakpoint error

I am trying to open a xml file from my Assets folder, but unfortunately I am only able to open my xml file by using a FileOpenPicker which is not the most ideal situation when I have to constantly fetch my xml file, without disturbing the user of course.
FileOpenPicker^ openPicker = ref new FileOpenPicker();
openPicker->ViewMode = PickerViewMode::List;
openPicker->SuggestedStartLocation = PickerLocationId::Desktop;
openPicker->FileTypeFilter->Append(".xml");
task<StorageFile^>(
openPicker->PickSingleFileAsync()).then([this](StorageFile^ file) {
if (nullptr != file) {
task<Streams::IRandomAccessStream^>(file->OpenAsync(FileAccessMode::Read)).then([this](Streams::IRandomAccessStream^ stream)
{
IInputStream^ deInputStream = stream->GetInputStreamAt(0);
DataReader^ reader = ref new DataReader(deInputStream);
reader->LoadAsync(stream->Size);
String^ strXml = reader->ReadString(stream->Size);
});
}
});
I am now trying to reconstruct this code into a code which loads up my xml file without letting the user choose. I tried the following approach:
String^ xmlFile = "Assets\MyXmlFile.xml";
StorageFolder^ InstallationFolder = Windows::ApplicationModel::Package::Current->InstalledLocation;
task<StorageFile^>(
InstallationFolder->GetFileAsync(xmlFile)).then([this](StorageFile^ file) {
if (nullptr != file) {
task<Streams::IRandomAccessStream^>(file->OpenAsync(FileAccessMode::Read)).then([this](Streams::IRandomAccessStream^ stream)
{
IInputStream^ deInputStream = stream->GetInputStreamAt(0);
DataReader^ reader = ref new DataReader(deInputStream);
reader->LoadAsync(stream->Size);
String^ strXml = reader->ReadString(stream->Size);
stream->FlushAsync();
});
}
});
I think I get errors at the GetFileAsync which I am not able to solve and I am asking you, the community to try and help me.
Your code worked for me with one modification: the xmlFile string contains a backslash that needs to be escaped:
String^ xmlFile = "Assets\\MyXmlFile.xml";
Note also that if you just right-clicked "Assets" in your project and chose "Add new item", that item may have ended up in your root project folder (which is the default). If you want it to be deployed to the Assets subfolder it will need to physically live there on disk in the assets subdirectory, not just be in the Assets filter. (Unlike in C#, the C++ project "folders" are actually filters and do not reflect physical directory location.)

Default Directory in Rogue Wave

I am trying to get IlvFileChooser to open in a default directory but can't find any option to do that. Any ideas please?
IlvFileChooserOptions* opt = new IlvFileChooserOptions(IlvFileChooserOpen);
opt->addFilter("Comma separated files (*.csv)", "csv");
IlvFileChooser* dlg = new IlvFileChooser(SIDGetDisplay(), 0, 0, opt);
if (dlg->get() > 0)
{
...
}
From the rogue-wave documentation, it seems like the second argument to IlvFileChooser is the default directory.
The documentation is you want is here.

WooCommerce - require php file for specific category

I'm trying to add :
require get_template_directory() . '/mytheme/folder/file.php';
To specific category in WooCommerce, I tried already:
function get_file() {
if( has_term( 'categoryName', 'product_cat' ) ) {
require get_template_directory() . '/mytheme/folder/file.php';
}
}
add_action( 'woocommerce_before_main_content', 'get_file');
But it doesen't work ;/
How can i add this file only for 1 category?
Or for multi cat. by using else if
Regards, Gabrielle
I'm surprised you aren't getting a PHP error for the file not existing. But check out the get_template_directory() function. It gives you the path to the current theme folder. Therefore I think your path is probably wrong since your theme folder is being repeated... something akin to SOME_PATH_STUFF/wp-content/themes/mytheme/mytheme/folder/file.php
Try the following instead:
function get_file() {
if( has_term( 'categoryName', 'product_cat' ) ) {
require get_template_directory() . '/folder/file.php';
}
}
add_action( 'woocommerce_before_main_content', 'get_file');

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");