这是我的代码到目前为止:
// locate the node(s)
XPath xpath = XPathFactory.newInstance().newXPath();
NodeList nodes = (NodeList)xpath.evaluate("//root[text()='input[1]']", doc, XPathConstants.NODESET);
// make the change
for (int idx = 0; idx < nodes.getLength(); idx++) {
nodes.item(idx).setTextContent(input[3]);
}
// save the result
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(new DOMSource(doc), new StreamResult(new File(outputFile)));
Run Code Online (Sandbox Code Playgroud)
输入[1]是我在XML中寻找的东西,输入[3]就是它被替换的内容.
这是XML:
<root>
<accounts>
<account name="Bill Gates">
<position>CEO</position>
<phoneNumber>123-485-1854</phoneNumber>
<notes>Runs the company</notes>
</account>
<account name="Service Account"/>
<account name="Burt Mackland">
<position>CFO</position>
<phoneNumber>345-415-4813</phoneNumber>
<notes>Great CFO</notes> </account>
<account name="Joe Smith">
<position>Accountant</position>
<reportsTo>Burt Mackland</reportsTo>
<phoneNumber>135-118-7815</phoneNumber>
<notes>Must have ID checked at …Run Code Online (Sandbox Code Playgroud) 嗨,我是QT创作者的新手.我已经尝试了很多东西来设置Q主窗口的背景图像.我在图片中添加了一个资源文件夹.我尝试在UI中使用setstylesheet添加,并尝试编码.当我使用UI时,我可以看到图像,但是当我运行它时,没有任何显示.我想把一张扑克桌的图像作为背景,并且能够将按钮等放在上面.
main.cpp中:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setStyleSheet("{background-image: url(:/images/images/PokerTableBackground.jpg);}");
}
MainWindow::~MainWindow()
{
delete ui;
}
Run Code Online (Sandbox Code Playgroud)
就像我说的那样,我尝试过这样做,并将图像放在UI中,而且其中任何一个都不起作用.我想将图像设置为整个事物的背景.
我也试过用这个:
QWidget *pic = new QWidget(ui->tab);
pic->setStyleSheet("background-image: url(:/images/images/PokerTableBackground.jpg)");
pic->setGeometry(QRect(10,10,220,48)); // your location and size.
Run Code Online (Sandbox Code Playgroud) 我有一个方法,假设将类名,参数和方法名称作为参数,并根据它找到的类调用该方法.方法:
Method[] methods = className.getDeclaredMethods();
for (Method meth: methods) {
if (meth.getName().equalsIgnoreCase(methodName)) {
try {
MethodType mt = MethodType.methodType(boolean.class, String.class);
MethodHandles.Lookup caller = MethodHandles.lookup();
MethodHandle handle = caller.findVirtual(Utilities.class, meth.getName(), mt);
/*
* Trying to invoke using lambdaMetaFactory
*/
MethodType methodType = MethodType.methodType(boolean.class);
MethodType invokedType = MethodType.methodType(BooleanSupplier.class);
/*
* Throws java.lang.invoke.LambdaConversionException: Incorrect number of parameters for instance method
* invokeVirtual com.grainger.Automation.Utilities.navigateToUrl:(String)boolean; 0 captured parameters,
* 0 functional interface method parameters, 1 implementation parameters
*/
CallSite site = LambdaMetafactory.metafactory(caller, "getAsBoolean", invokedType, methodType, …Run Code Online (Sandbox Code Playgroud)