I have to say I'm kinda newbie with QT stuff.
I've tried to get to work Phonom using sample of code:
audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
mediaObject = new Phonon::MediaObject(this);
metaInformationResolver = new Phonon::MediaObject(this);
Phonon::createPath(mediaObject, audioOutput);
mediaObject->setCurrentSource(Phonon::MediaSource(":/sound/beep.wav"));
mediaObject->play();
The only warning that apears while compilation is:
"WARNING: Phonon::createPath: Cannot connect Phonon::MediaObject ( no objectName ) to Phonon::AudioOutput ( no objectName ). " - it's results with no sound.
I tried to set device output by hand with no results. Meanwhile checked qmediaplayer example - which works fine.
Does anyone can tell me, what I'm doing wrong?
QT += phonon also included
well first of all I'm not sure why you are calling create path() 2 times at line 3 and 5 with same arguments then i'll try setting source before connecting but i don't think this are the real problems
to me this worked:
Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput();
Phonon::MediaObject *mediaObject = new Phonon::MediaObject();
mediaObject->setCurrentSource(Phonon::MediaSource("PathToFile"));
Phonon::createPath(mediaObject, audioOutput);
Phonon::MediaObject *metaInformationResolver = new Phonon::MediaObject();
mediaObject->play();
Related
When I add the formula FORECAST.ETS, it adds an # after the equal symbol, like this: = #FORECAST.ETS. Why is this happening?
The code snippet is:
ws.cell(column=1, row=2, value="=FORECAST.ETS(...)"
When I open it with Excel (latest Office 365 version), it shows as =#FORECAST.ETS(..)
I have hit the same issue, but not with Python and openpyxl, but with dotnet Core C# and EPPLUS. What follows is perhaps a workaround based on my findings... but not ideal. I suspect it will work with openpyxl too.
Re-creating the problem
I have written a simplified C# console app that firstly creates a new XLSX (foo.xlsx), writes out some data and my formula, and then outputs the cell with the formula and the value to the Console. It then saves and closes the XLSX, and reopens it and again outputs the formula cell and its value. The code is as follows:
using OfficeOpenXml;
using System;
using System.IO;
namespace TestFormula
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Test starts");
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
if (File.Exists($".\\foo.xlsx"))
{
File.Delete($".\\foo.xlsx");
}
using (var ep = new ExcelPackage(new FileInfo($".\\foo.xlsx")))
{
ExcelWorkbook wb = ep.Workbook;
ExcelWorksheet wsTest = null;
wsTest = wb.Worksheets.Add("Test");
// Add some look up data...
for (int row = 1; row <= 5; row++)
{
wsTest.Cells[row, 1].Value = row;
wsTest.Cells[row, 2].Value = $"Name {row}";
}
wsTest.Cells[1, 4].Formula = $"=XLOOKUP($A3,$A:$A,$B:$B))";
Console.WriteLine($"Add: formula=\"{wsTest.Cells[1, 4].Formula}\"");
Console.WriteLine($"Add: value=\"{wsTest.Cells[1, 4].Value}\"");
ep.Save();
ep.Dispose();
}
using (var ep = new ExcelPackage(new FileInfo($".\\foo.xlsx")))
{
ExcelWorkbook wb = ep.Workbook;
ExcelWorksheet wsTest = null;
wsTest = wb.Worksheets["Test"];
Console.WriteLine($"Open: formula=\"{wsTest.Cells[1, 4].Formula}\"");
Console.WriteLine($"Open: value=\"{wsTest.Cells[1, 4].Value}\"");
ep.Dispose();
}
Console.WriteLine("Test ends");
}
}
}
The output from the above looks like this...
Note that the formula after closing and re-opening the XLSX with EPPLUS reads just as it was written.
However, if I open the file with Excel I can see that an # has been inserted after the = sign.
If I then double click on the formula cell, I get an Excel error message...
I answered "no" to this question because I wanted to continue to experiment with what was happening behind the scenes.
After double clicking the formula cell to edit it, when I now hit ENTER with the # in the formula, it works. At this point I save the XLSX with the change made.
If I now delete some of my code and just run...
using OfficeOpenXml;
using System;
using System.IO;
namespace TestFormula
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Test starts");
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
using (var ep = new ExcelPackage(new FileInfo($".\\foo.xlsx")))
{
ExcelWorkbook wb = ep.Workbook;
ExcelWorksheet wsTest = null;
wsTest = wb.Worksheets["Test"];
Console.WriteLine($"Open: formula=\"{wsTest.Cells[1, 4].Formula}\"");
Console.WriteLine($"Open: value=\"{wsTest.Cells[1, 4].Value}\"");
ep.Dispose();
}
Console.WriteLine("Test ends");
}
}
}
I get the following output...
What's particularly interesting about the output is that the formula has been modified by Excel and has been prefixed with _alfn.SINGLE.
Research
It is worth declaring here that I am running Microsoft 365 and I always have patches and updates automatically applied as soon as they become available. So my version of Excel is the latest version.
Google-ing for _alfn.SINGLE provides a number of hits (see References below) and from these I have concluded the following:
In Aug 2019 Microsoft released an update that introduced a new formula keyword called XLOOKUP... intended to replace VLOOKUP and HLOOKUP. As such, the XLSX file format was updated to allow for this new feature. The second reference below mentions dates of the introduction of other formulas around Sep 2018.
I'm guessing that the EPLUS library (and probably the openpyxl) have not updated their file format to compensate for the addition of these new/changed features.
When Excel opens an older file version and detects a more recent formula keyword (i.e. a keyword that was not available in the earlier file version), it does not automatically resolve the formula, but instead throws the error I mentioned above, and then resolves the problem by prefixing the new formula keyword with _alfn.SINGLE.
Solution
It's dirty and short term until the EPPLUS/openpyxl libraries catch up. In my case, in code simply replace...
wsTest.Cells[1, 4].Formula = $"=XLOOKUP($A3,$A:$A,$B:$B)";
... with ...
wsTest.Cells[1, 4].Formula = $"_xlfn.SINGLE(_xlfn.XLOOKUP($A3,$A:$A,$B:$B))";
References
Issue: An _xlfn. prefix is displayed in front of a formula by Microsoft
XLOOKUP XMATCH FILTER RANDARRAY SEQUENCE SORT SORTBY UNIQUE CONCAT IFS MAXIFS MINIFS SWITCH TEXTJOIN by Andreas Killer
I just started using SALT for a project i am working on. It is said to work with Python but I find quite a bit of difference in thier syntax and overall format. I have pasted a code for a simple task which just opens and imports and loads some libraries onto the SALT console. I hope someone can check abnd see if he/she can instantly identify the language being used and what the code does. This is because i have a suspicion that the code is a mixture between C, Python as well as Java... if that is so doen't that mean it should be a totally different language on its own?
code:
var rtwxlib = import'rtwxlib';
var string = import'string';
var monitor = rtwxlib.Monitor
{
EvActivate = func() { print "Activate\n"; };
EvShutdown = func() { print "Shutdown\n"; };
EvProgress = func(self, fDone, msg = "") {
print("Progress: %d %s \r"::format(fDone*100, msg));
};
EvEventMsg = func(self, msg) {
print("\nEvent: %s\n"::format(iStat, msg));
};
};
var solver = rtwxlib.Solver(monitor);
solver::Open("test.wrx");
solver::DelGeometry();
solver::SaveAs('testresults.wrx');
solver::Close();
I was able to indentify the syntax of the language used as C. I beieve the problem I had which confused me was the libraries used for this code which I later found out was for a particular program. Thank you to all those who tried to help though :)
I have a problem running phantomjs.exe binary in my QProcess class. Consider this code:
QString program = "phantomjs.exe";
QProcess *process = new QProcess(this);
process->start(program, QStringList() << "test.js");
When I start the app main process loads up and nothing happens after that, just hundreds of other phantomjs.exe are created (checking it in TaskManager) as well as conhost.exe processes.
I tried other exe files, like notepad.exe, and it works just fine. Notepad window appears.
Did you encounter this problem?
Do you call phantom.exit() in your test script?
https://github.com/ariya/phantomjs/wiki/Quick-Start
console.log('Hello, world!');
phantom.exit();
Hope that helps.
After checking I found that there is a problem with QProcess. I used SHELLEXECUTEINFO instead. This code works for me well. No recursive calls of phantomjs.exe here:
SHELLEXECUTEINFO shExecInfo;
shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
shExecInfo.fMask = NULL;
shExecInfo.hwnd = NULL;
shExecInfo.lpVerb = L"runas";
shExecInfo.lpFile = L"phantomjs.exe";
shExecInfo.lpParameters = L"test.js";
shExecInfo.lpDirectory = NULL;
shExecInfo.nShow = SW_NORMAL;
shExecInfo.hInstApp = NULL;
ShellExecuteEx(&shExecInfo);
We have Adobe PDF writer and would like to be able to use this instead of ghostscript. Is the SaveAs() function locked into ghostscript and, if so, how can I use adobe pdf writer to get around this?
I think this could be the solution:
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc00844_1150/html/pbug/pbug526.htm
The key change is that you need to create your own printer not using the GhostScript files than the files shipped with Adobe.
I think you should create your Adobe PDF Printer in this way:
http://www.ehow.com/how_5782035_add-adobe-pdf-printer.html
So you should add a local printer with using this file:
C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Xtras\AdobePDF". Click the
"AdobePDF.inf"
After this the code should something similar to this:
int li_ret
dw_1.Object.DataWindow.Export.PDF.Method = Distill!
dw_1.Object.DataWindow.Printer = "YourAdobePDFPrinterName"
dw_1.Object.DataWindow.Export.PDF.Distill.CustomPostScript="Yes"
li_ret = dw_1.SaveAs("custom.PDF", PDF!, true)
Of course there could be many other problems with printing. Feel free to ask!
Br.: Gábor
The SaveAs() function is tied to using Ghostscript, to print using Adobe Acrobat, you treat it as a regular printer. Hopefully PB 9 has these functions as this is taken from PB 11.5.
RegistrySet("HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\9.0\AdobePDFOutputFolder", "", ReguLong!, 2)
RegistrySet("HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\9.0\AdobePDFOutputFolder", "2", RegString!, "C:\_APPS")
//Gets the default printer
ls_default = PrintGetPrinter()
//Parses string
ll_pos = Pos(ls_default, "~t")
is_default_printer = Left(ls_default, ll_pos - 1)
//Gets the Printers on the computer
ls_printers = PrintGetPrinters( )
//Finds the Distiller printer
ll_pos = PosA(ls_printers, "Acrobat Distiller")
//Checks for newer version of Distiller
if (ll_pos = 0) then
ll_pos = PosA(ls_printers, "Adobe PDF")
end if
//Gets the location of the Distiller printer
ls_printer = MidA(ls_printers, ll_pos, PosA(ls_printers, ":", ll_pos) - ll_pos + 1)
//Sets our next print ll_job to print to Distiller
PrintSetPrinter(ls_printer)
//Allocates memory for our DS
DS = create DataStore
//Opens Print Job
ll_job = PrintOpen("MyPDF", false)
//Checks for error
if (ll_job > 0) then
//First Datastore to add to the PDF
DS.DataObject = "d_wlcp_view"
DS.SetTransObject(SQLCA)
DS.Retrieve(idt_review_date, ii_site_id)
PrintDataWindow(ll_job, DS)
//You can add more pages to the PDF by printing more DW's or DS's
DS.DataObject = "d_training_view"
DS.SetTransObject(SQLCA)
DS.Retrieve(idt_review_date, ii_site_id)
PrintDataWindow(ll_job, DS)
//Closes the print job
PrintClose(ll_job)
//Sets the default printer back
PrintSetPrinter(ls_default)
//Sometimes the PB function doesn't set the printer back, so you can use
//this VB script to make sure it is set back to the default
//Run('cscript C:\_APPS\HWLCPRR\prnmngr.vbs -t -p "' + is_default_printer + '"')
//Deallocates memory for DS
if (isValid(DS)) then destroy DS
Here is the VB Script.
My english is not very good but i’ll try to describe my problem.
So, i have primitive code:
base = QSqlDatabase::addDatabase("QODBC");
QSettings sets("FlowModel","Settings");
currentBase = sets.value("currentBase").toString();
base.setHostName("localhost");
base.setDatabaseName(QString("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=%1").arg(currentBase));
if(base.open())
QMessageBox::information(0,"Все отлично!","База данных открыта","Ок");
else
QMessageBox::information(0,"Все не ахти!",base.lastError().text(),"Ок");
QSqlQuery queryMaterials("SELECT * FROM Материал",base);
int fieldNo = queryMaterials.record().indexOf("Название");
int i = 0;
while (queryMaterials.next()) {
comboBox->insertItem(i++,queryMaterials.value(fieldNo).toString());
}
queryMaterials.clear();
It works correctly and combo box takes all materials from Database;
But next is going this code:
QSqlQuery queryInfo("SELECT * FROM Свойства_материала WHERE Название='Вода'",base);
fieldNo = queryInfo.record().indexOf("P");
pLine->setText(queryInfo.value(fieldNo).toString());
And it didn’t work! Query returns an empty string (”“), but must be a number. I test this SQL-query in Access and there it works correct. Please help to understand what a problem i have.
Thank you.
P.S. I’m tried to use QSqlQuery::lastError().text() method, but it report me nothing.
I can’t understand what is that… Because this table can be opened by this code:
QSqlDatabase accessBase = QSqlDatabase::addDatabase("QODBC");
accessBase.setHostName("localhost");
accessBase.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=D:/ИТ.mdb");
if(accessBase.open())
QMessageBox::information(0,"Все отлично!","База данных открыта","Ок");
else
QMessageBox::information(0,"Все не ахти!",accessBase.lastError().text(),"Ок");
QTableView tableGhost;
QSqlTableModel tableDB;
QString whtpn = QInputDialog::getText(0, "Какую таблицу открыть?",
"Какую таблицу открыть?");
tableDB.setTable(whtpn);
tableDB.select();
tableDB.setEditStrategy(QSqlTableModel::OnFieldChange);
tableGhost.setModel(&tableDB);
tableGhost.show();
And all ok. But by query no(
Problem has been solved.
Before line
pLine->setText(queryInfo.value(fieldNo).toString());
Had to use method QSqlQuery::next();